Forum Moderators: phranque

Message Too Old, No Replies

Problem with http to https 301

Redirecting some fine others not

         

FattyB

5:21 pm on Aug 24, 2017 (gmt 0)

10+ Year Member



Moving site to https from http.

Have installed cert etc.

The 301 I have is
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


It is working fine for urls like mysite.com/blah/blah/ but ones with mysite.com/blah/blah/blah/ are redirected to the home page

Any ideas?

Thanks
James


[edited by: not2easy at 6:28 pm (utc) on Aug 24, 2017]
[edit reason] readability [/edit]

whitespace

6:10 pm on Aug 24, 2017 (gmt 0)

10+ Year Member Top Contributors Of The Month



It's either a caching issue (make sure you've cleared your browser cache), or "something else". In isolation, there's nothing with that directive that would result in different behaviour between "/blah/blah/blah/" and "/blah/blah/".

Where are these directives? .htaccess file or server config? Do you have any other directives? Do you have any other `.htaccess` files (eg. "/blah/blah/blah/.htaccess")?

You are not canonicalizing the hostname (ie. www or no-www)? Or is this done somewhere else? The URL canonicalization (ie. www and HTTPS) are usually done together.

not2easy

6:27 pm on Aug 24, 2017 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Mod_Rewrite does not inherit so if there are .htaccess files in any folders/directories, they never see that root directory rewrite. The target (destination URL) should not use that {HTTP_HOST} because it does not mean "your domain name" it means whatever domain is requested. You should spell out the domain name as in:
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]

RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Note that using [ code ] tags and/or example.com in place of actual or artificial domain names will prevent their linking and save the Mods time taken to make the post readable - Thanks!

FattyB

2:45 am on Aug 28, 2017 (gmt 0)

10+ Year Member



Thanks folks, was using htaccess.

I could not solve it except by manually redirecting each of them. There was a htaccess in the folder but I renamed it before posting. Everything else worked fine, though I changed it to be more specific as per your advice. All working now but still no wiser as to why just those with two folders refused to redirect.