LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Apache Rewrite (https://www.linuxquestions.org/questions/linux-software-2/apache-rewrite-682387/)

mahmoud 11-10-2008 11:02 AM

Apache Rewrite
 
Hi
i want to setup my ssl vhost and i have a bit of a problem
first i want to redirect the links to home page if its not secure
e.g
http://secure.myserver.com should go back to http://myserver.com
but
https://secure.myserver.com should stay on https://secure.myserver.com
and when on the https or secure link if they leave the pages that are secure they should be redirected back to http://myserver.com
i am using fedora 9 64bit
also i have alot of rewrites in there for the alias domains i have and i want it to affect all the

mazhar_theone 11-10-2008 02:42 PM

Quote:

Originally Posted by mahmoud (Post 3337259)
Hi
i want to setup my ssl vhost and i have a bit of a problem
first i want to redirect the links to home page if its not secure
e.g
http://secure.myserver.com should go back to http://myserver.com
but
https://secure.myserver.com should stay on https://secure.myserver.com
and when on the https or secure link if they leave the pages that are secure they should be redirected back to http://myserver.com
i am using fedora 9 64bit
also i have alot of rewrites in there for the alias domains i have and i want it to affect all the



You can use HTTP_HOST , SERVER_PORT in rewrite conditions to do this.
for e.g.

RewriteCond %{HTTP_HOST} !^secure\.myserver\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) http://myserver.com/$1 [L,R]

This example should redirect all insecure url which math HTTP_HOST secure.myserver.com to http://myserver.com. you can add [OR] to add multiple conditions for HTTP_HOST.

You can use following rewrite rule to redirect all insecure URL's to secure without changing the HTTP_HOST(domain in URL) or REQUESTED_URL (files / URL requested)

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

mahmoud 11-11-2008 07:52 AM

thanks thats working one more thing i what it to be that when you are on the link
https://myserevr.com goes to http://myserver.com
http://secure.myserver.com to goto http://myserver.com this is working
but when there is something like
http://secure.myserver.com/secure/page to be redirected to https://secure.myserver.com/secure/page


All times are GMT -5. The time now is 05:09 AM.