Forum Moderators: phranque

Message Too Old, No Replies

Redirect to get rid of SSL dup content

         

Philosopher

5:15 pm on Jul 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A client is having issues with his site being spidered under https instead of http.

Obviously, I want to redirect the https requests to http, but only some of them as parts of the site do require SSL.

This is basically what I need...anything that is in a subfolder should be able to be accessed via SSL, any page in the root should only be able to be accessed via standard http connections.

All pages in the root should end in either .htm or .html with filenames made up of letters, numbers, and hyphens.

Will something such as the following work or is there a more streamlined way to handle this?

RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^([^/]+)\.html$ http://www.example.com/$1.html [R=301,L]

RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^([^/]+)\.htm$ http://www.example.com/$1.htm [R=301,L]

Thanks!

jdMorgan

7:14 pm on Jul 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like you've almost got it, but you don't need two rules. Just make the trailing "l" optional by using the "0 or 1" quantifier "?" after it.

Also, I suspect you'll want to include the "html?" in the back-reference, so that a request for "htm" will stay as "htm" and one for "html" will stay "html":


RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^([^/]+\.html?)$ http://www.example.com/$1 [R=301,L]

If you need to enforce SSL in any and all subdirectories, then you'd need another rule, and it would be sort of "opposite" the first:

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(([^/]+/)+.*)$ https://www.example.com/$1 [R=301,L]

That will force all requests for all resources in all subdirectories (at all depths) to https.

Jim

Philosopher

8:37 pm on Jul 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perfect...Thanks Jim