cPanel & WHM Version 98 has been released, and brings a slew of great updates. Take a look at what is included, and then upgrade today!

Have redirect code prepended to .htaccess when setup through cPanel

Eclipse Creative shared this idea 21 months ago
Open Discussion

As a cPanel user, I would like the rules added to the .htaccess file when a redirect is setup within cPanel to be prepended to the file instead of appended, as the redirect doesn’t work unless those rules are at the top of the file.


============


My Request stems from a support request I'd made and the cPanel representative prompted me to post here.


In short I feel the rules added to the .htaccess file when a redirect is setup within cPanel should be prepended to the file instead of appended. As when it's appended it's useless and doesn't redirect so users have to manually move the rules to the top of the file.


My original query;

=================================

Hello,

I was trying to redirect my domain with a Wildcard redirect and had found that it didn't redirect the root of the domain but the files would be. Investigating I found the .htaccess file had the redirect code but it had been appended after the WordPress htaccess code causing the redirect to be completely ignored.

I would suggest having the redirect code prepend rather than append to the .htaccess to avoid this.

FYI my .htaccess before I manually went and moved the cpanel injected code to the beginning of the file;

```

RewriteOptions inherit

# BEGIN WordPress

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$

RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$

RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$

RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$

RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$

RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$

RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$

RewriteRule . /index.php [L]

</IfModule>

# END WordPress

# Wordfence WAF

<Files ".user.ini">

<IfModule mod_authz_core.c>

Require all denied

</IfModule>

<IfModule !mod_authz_core.c>

Order deny,allow

Deny from all

</IfModule>

</Files>

# END Wordfence WAF

RewriteCond %{HTTP_HOST} ^.*$

RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$

RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$

RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$

RewriteRule ^(.*)$ "https\:\/\/eclipse3sixty\.com\/$1" [R=301,L]

```

I hope that makes sense.Cheers

Steps to reproduce:

1. Create an account on WHM

2. Install WordPress into new account

*May also need to install Wordfence as I noticed it's also evident in the .htaccess

3. Verify site loads

4. Through cPanel do a wildcard redirect on that domain.

5. Navigate to site it will load but all it's resources won't.

6. Inspect the .htaccess file and you'll find redirect code was appended, moving it to the top of the .htaccess resolves the redirect.

=================================


cPanel Representatives Response;

=================================

Hello,

Thank you for contacting cPanel, we really appreciate your insight on this. I've faced this myself on numerous occasions in which if an .htaccess file already exists in a given location, the rules get appended, requiring user to place them at the top of the file for them to become active.

Doing a bit of research on the current process. From what I gathered, the appending method is more universal for if file isn't present then the rules would be added creating the file and in functioning order, where as if an existing .htaccess is already present, one would have to manually place rules at the top for them to become active.

One of the concerns and possible issues with prepending to the file would have to do with the existing lines that are already present, this could pose a greater risk in negatively affecting a sites availability in some cases.

At the same time it would also be a nice feature as well for redirect could be applied and working with no additional adjustments outside of adding it.

You can submit a feature request for our developers to further look into.

https://features.cpanel.net

=================================

Leave a Comment
 
Attach a file