301 redirect in the htaccess file issues
This is driving me crazy, can anybody tell me why this 301 redirect does not work. I just get a 404 error with the old /about page. Here is the code for info:
ENV:WPR_SSL.html%ENV:WPR_ENC" -f
RewriteRule .* "/wp-content/cache/wp-rocket/%HTTP_HOST%REQUEST_URI/index%ENV:WPR_SSL.html%ENV:WPR_ENC" [L]
</IfModule>
# END WP Rocket
RewriteEngine on
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Redirect 301 /about https://scottcarneyphotography.com/about
RewriteRule ^index.php$ - [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteEngine On
RewriteCond %HTTPS off
RewriteRule ^(.*)$ https://%HTTP_HOST%REQUEST_URI [L,R=301]
RewriteEngine on
Redirect 301 /about https://scottcarneyphotography.com/about
The Redirect
directive belongs to mod_alias and consequently runs after the existing mod_rewrite directives in your config file, this is possibly resulting in a conflict.
You should move this redirect to the top of your .htaccess
file and convert it to mod_rewrite instead. For example:
RewriteRule ^about$ https://scottcarneyphotography.com/about [R=301,L]
However, there are other potential issues with your .htaccess
file...
ENV:WPR_SSL.html%ENV:WPR_ENC" -f
RewriteRule .* "/wp-content/cache/wp-rocket/%HTTP_HOST%REQUEST_URI/index%ENV:WPR_SSL.html%ENV:WPR_ENC" [L]
</IfModule>
# END WP Rocket
I guess you're not showing your complete config file, however, these directives are literally chopped in half - so they don't look valid. There may also be directives earlier in the file that may conflict with your redirect.
RewriteEngine On
RewriteCond %HTTPS off
RewriteRule ^(.*)$ https://%HTTP_HOST%REQUEST_URI [L,R=301]
These directives (at the end of the .htaccess
file, after the WordPress front-controller) are in the wrong place and consequently will not work as intended (to redirect all traffic to HTTPS). They should be near the top of your .htaccess
file, before the WordPress front-controller.
RewriteEngine on
There's no need for spurious/multiple RewriteEngine
directives strewn, seemingly arbitrarily, throughout the config file. You only need one of these. (Keep the one inside the # BEGIN WordPress
block.)
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
:
</IfModule>
# END WordPress
You should avoid manually editing the directives between the # BEGIN WordPress
and # END WordPress
comment markers. This is maintained by WordPress, so could be overwritten by WordPress in future updates (unless you have explicitly blocked WP from doing this).
Check please if add to top .htaccess
file (before WP Rocket rewrites) this 301 redirect work.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^about/$ https://scottcarneyphotography.com/about/ [R=301,L]
</IfModule>
Wordpress default add /
to end of URL address, maybe request is /about/
not /about
.
Comments
Post a Comment