Welcome to WebmasterWorld Guest from 54.156.58.187

Forum Moderators: Ocean10000 & incrediBILL & phranque

Problem with http to https 301

Redirecting some fine others not

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

Full Member

10+ Year Member

joined:July 6, 2005
posts:316
votes: 19


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]

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

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 300
votes: 21


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.
6:27 pm on Aug 24, 2017 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:3451
votes: 181


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!
2:45 am on Aug 28, 2017 (gmt 0)

Full Member

10+ Year Member

joined:July 6, 2005
posts:316
votes: 19


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.