Reputation: 12034
Here is my simple .htaccess My goal is simply to add a rule that redirects /faq -> faq.php on my HTTPS server.
# force ssl
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R]
RewriteRule faq faq.php
I also tried with:
RewriteRule faq faq.php
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R]
This works fine if I uncomment the http->https redirection rule.
so what I try to do is:
->if http, then redirect to https
->if /faq then redirect to faq.php
When I remove these lines
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R]
faq->faq.php works but I lose the http->https redirection of my whole website
Upvotes: 0
Views: 477
Reputation: 1280
You should have at least one RewriteCond
for each RewriteRule
.
Try
RewriteCond %{REQUEST_URI} ^/faq$
RewriteRule ^(.*)$ https://%{SERVER_NAME}/faq.php [R]
after the first two lines (instead of the third).
EDIT:
As I meant, it was
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R]
RewriteCond %{REQUEST_URI} ^/faq$
RewriteRule ^(.*)$ https://%{SERVER_NAME}/faq.php [R]
That is, TWO RewriteCond
directives.
Upvotes: 1