Home .Htaccess redirect breaks file path
Reply: 2

.Htaccess redirect breaks file path

Matt Hammond
1#
Matt Hammond Published in 2018-02-12 18:33:15Z

I'm attempting to canonicalization my URL. However, when adding the relevant code, it breaks my other rewrite rules which allows me to hide the .html/ .php. It works fine when landing on the homepage but when you go to a page with www. and a file path at the end of the URL the page redirects to the homepage without www.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]

RewriteCond %{HTTP_HOST} ^www\.bespoke-apertures\.co.uk$ [NC]
RewriteRule (.*) https://bespoke-apertures.co.uk/$1 [R=301,L]
anubhava
2#
anubhava Reply to 2018-02-13 16:54:24Z

Have it like this in different order:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.(bespoke-apertures\.co.uk)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [L,QSA]

Make sure to test this in a new browser to avoid old cache.

prakash tank
3#
prakash tank Reply to 2018-02-12 18:43:53Z

Try this to redirect without www :

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]  
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316157 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO