views:

97

answers:

1

I would like to redirect all connections from htt_p://www.example.com/abc.html to HTTP_S://www.example.com/abc.html . What mod_alias or mod_rewrite commands would work for this? I've tried:

RewriteEngine on
RewriteCond %{HTTPS} =off
RewriteRule $abc\.html^ https://www.example.com/abc.html [R]

in both .htaccess and httpd.conf but that doesn't work. It works if the first string in the RewriteRule is anything else (like abz.html) but not if it is abc.html. abc.html is a real file on the server (not another redirect). Options FollowSymlinks is present in the appropriate Directory directive.

Many thanks.

+1  A: 

Something along the lines of the following will allow you to redirect non-SSL pages to SSL versions (assuming that you are running SSL on port 443):

RewriteEngine on

# Limited redirects
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} ^/abc\.html$ [OR,NC]
RewriteCond %{REQUEST_URI} ^/def\.html$ [OR,NC]
RewriteCond %{REQUEST_URI} ^/ghi\.html$ [NC]
RewriteRule ^/(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

The [OR] flag after the RewriteCond is literally that, "or", which is why the last condition doesn't have it

Cez
Thanks, but that still doesn't solve the issue. It works in redirecting /aBc.html appropriately, but not abc.html. It seems like if Apache sees the real file there, it gives the real file precedence over any RewriteRule statements. Is there any way to force it to redirect even if the file exists? Thanks again!
BuyTheBid
Rewrites do take precedence over real files, which implies that the directives are possibly in the wrong place for their current format. Where, in precise terms, have you tried these rewrites (i.e. in .htaccess of directory, in Directory directive of config, in VirtualHost directive of config)? Also, can you post the full URL that matches and likewise for the one that doesn't?
Cez
Ok it's working now. Just putting it in my httpd.conf did the trick. I think the issue was that my browsers were caching the old pages.Thanks for your help, Cez!
BuyTheBid
Glad to have helped
Cez