fgasimzade
asked on
mod_rewrite Apache Windows Server
Hello everyone!
Can not configure mod rewrite in Apache with Windows Server. Seems like I have enabled it, but still no luck.
This is my .htaccess file
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^airport\.az$
RewriteRule ^(.*)$ http://www.airport.az/$1 [R=301,L]
RewriteRule ^.htaccess$ - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_REFERER} !^$
#RewriteRule .*\.(gif|jpg|png)$ - [F,L]
IndexIgnore *
RewriteRule ^(az|en|ru)/(download)/([a -z-]+)/([0 -9-]+)/?$ download.php?lang=$1&type= $3&id=$4 [NC,L]
RewriteRule ^(az|en|ru)/(map)/([0-9-]+ )/([0-9-]+ )/?$ map.php?lang=$1&id=$3&type =$4 [NC,L]
RewriteRule ^(az|en|ru)/([a-z0-9-]+)/( [0-9-]+)/? $ index.php?lang=$1&menu=$2& id=$3 [NC,L]
RewriteRule ^(az|en|ru)/(news-view+)/( [0-9-]+)/( [0-9-]+)/? $ index.php?lang=$1&menu=$2& id=$3&news =$4 [NC,L]
RewriteRule ^(az|en|ru)/([a-z0-9-]+)/( [0-9-]+)/( [0-9-]+)/? $ index.php?lang=$1&menu=$2& id=$3&star t=$4 [NC,L]
RewriteRule ^(az|en|ru)/([a-z0-9-]+)/? $ index.php?lang=$1&menu=$2 [NC,L]
RewriteRule ^(az|en|ru)/?$ index.php?lang=$1 [NC,L]
</IfModule>
When I try to load airport.az it gives me "Too many redirects error" in Chrome
Not sure what I need to change in conf file of Apache, I am using Virtual Hosts
I am not a web programming guy, I am a Cisco guy, but I just need to make it work
Thank you in advance!
Can not configure mod rewrite in Apache with Windows Server. Seems like I have enabled it, but still no luck.
This is my .htaccess file
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^airport\.az$
RewriteRule ^(.*)$ http://www.airport.az/$1 [R=301,L]
RewriteRule ^.htaccess$ - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_REFERER} !^$
#RewriteRule .*\.(gif|jpg|png)$ - [F,L]
IndexIgnore *
RewriteRule ^(az|en|ru)/(download)/([a
RewriteRule ^(az|en|ru)/(map)/([0-9-]+
RewriteRule ^(az|en|ru)/([a-z0-9-]+)/(
RewriteRule ^(az|en|ru)/(news-view+)/(
RewriteRule ^(az|en|ru)/([a-z0-9-]+)/(
RewriteRule ^(az|en|ru)/([a-z0-9-]+)/?
RewriteRule ^(az|en|ru)/?$ index.php?lang=$1 [NC,L]
</IfModule>
When I try to load airport.az it gives me "Too many redirects error" in Chrome
Not sure what I need to change in conf file of Apache, I am using Virtual Hosts
I am not a web programming guy, I am a Cisco guy, but I just need to make it work
Thank you in advance!
you're missing:
RewriteCond %{HTTP_HOST} !^www\.airport\.az$
RewriteCond %{HTTP_HOST} !^www\.airport\.az$
ASKER
@ahoffmann, I have tried this as well, the result is the same.
@arnold AllowOveride All is also included in httpd.conf under <Directory "C:/Program Files/Apache Group/Apache2/htdocs">
I would like to mention that I decided to make changes to httpd.conf instead of htaccess since I am using VirtualHosts. I found somewhere on the internet that with Virtual Hosts I have to configure redirection under Virtual Hosts.
One more thing to add. If I configure anything else than www.airport. redirection works. I mean something like this:
RewriteCond %{HTTP_HOST} ^airport\.az$
RewriteRule ^(.*)$ http://www.azal.az/$1 [R=301,L]
However, when I change www.azal.az to www.airport.az I get a redirection loop. Here is a part of my httpd.conf
<VirtualHost *:80>
ServerName www.airport.az
ServerAlias www.airport.az airport.az
DocumentRoot C:\Apache\Home\airport.az\ www
</VirtualHost>
@arnold AllowOveride All is also included in httpd.conf under <Directory "C:/Program Files/Apache Group/Apache2/htdocs">
I would like to mention that I decided to make changes to httpd.conf instead of htaccess since I am using VirtualHosts. I found somewhere on the internet that with Virtual Hosts I have to configure redirection under Virtual Hosts.
One more thing to add. If I configure anything else than www.airport. redirection works. I mean something like this:
RewriteCond %{HTTP_HOST} ^airport\.az$
RewriteRule ^(.*)$ http://www.azal.az/$1 [R=301,L]
However, when I change www.azal.az to www.airport.az I get a redirection loop. Here is a part of my httpd.conf
<VirtualHost *:80>
ServerName www.airport.az
ServerAlias www.airport.az airport.az
DocumentRoot C:\Apache\Home\airport.az\
</VirtualHost>
> ... the result is the same.
then please check your logfiles, it should contain hints about the redirects
post relevant messages if unsure
then please check your logfiles, it should contain hints about the redirects
post relevant messages if unsure
ASKER
Where can I find the logfiles?
look where your httpd.conf file within it there should be a reference to logfile location
likely where apache is installed \logs
likely where apache is installed \logs
ASKER
I found access logs and error logs but there is nothing there regarding redirection, as far as I understand
You have redirects that can match similar requests
Comment out a few of the redirects.
You have. Rule at the top that seemingly will match any request and then you have other redirect rules which is what the error say.
Redirectrule ^(.*)$ loops on the request for the domai request
I.e. $1 is blank so you keep redirecting http://www.yourdomain.com/ to itself without end.
Given that I have no idea what the common access pages you have, I can not evaluate the rules. Comment out all the rules except the top one. Then uncomment one at a time while trying the various access attempts until you enable the one that is conflicting. Then you can look at the request you are making and matching it to the lines and determining what the purpose of the redirects that matched.
What is the purpose of all the redirects?
You could define the root directory to use the index.php where you can then get the path and parse/convert the numerical strings and avoid the repetitive redirects.
Comment out a few of the redirects.
You have. Rule at the top that seemingly will match any request and then you have other redirect rules which is what the error say.
Redirectrule ^(.*)$ loops on the request for the domai request
I.e. $1 is blank so you keep redirecting http://www.yourdomain.com/ to itself without end.
Given that I have no idea what the common access pages you have, I can not evaluate the rules. Comment out all the rules except the top one. Then uncomment one at a time while trying the various access attempts until you enable the one that is conflicting. Then you can look at the request you are making and matching it to the lines and determining what the purpose of the redirects that matched.
What is the purpose of all the redirects?
You could define the root directory to use the index.php where you can then get the path and parse/convert the numerical strings and avoid the repetitive redirects.
> Redirectrule ^(.*)$ loops ...
it should not if my RewriteCond matches (see comment ID 37831638)
@fgasimzade, silly question: are airport.az and ww.airport.az the same IP *and* handled by the same httpd process?
it should not if my RewriteCond matches (see comment ID 37831638)
@fgasimzade, silly question: are airport.az and ww.airport.az the same IP *and* handled by the same httpd process?
ASKER
@ahoffmann, Yes, they are..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
How should I write a /path/to/your/rewrite.log here if it is in C:\Program Files\Apache Group\Apache2\logs
I get this error when I write it like
RewriteLog C:\Program Files\Apache Group\Apache2\logs\rewrite .log
[Thu Apr 12 14:08:39 2012] [alert] [client 85.132.43.8] C:/Apache/Home/airport.az/ www/.htacc ess: RewriteLog not allowed here
I get this error when I write it like
RewriteLog C:\Program Files\Apache Group\Apache2\logs\rewrite
[Thu Apr 12 14:08:39 2012] [alert] [client 85.132.43.8] C:/Apache/Home/airport.az/
RewriteLog* cannot be in .htaccess it must be in httpd.conf
BTW, are you aware that your .htaccess is consulted after all matching Directory, Location and Rewrite directives in your main httpd.conf have been evaluated?
it's a bad idea to have RewriteRules in .htaccess, IMHO ...
BTW, are you aware that your .htaccess is consulted after all matching Directory, Location and Rewrite directives in your main httpd.conf have been evaluated?
it's a bad idea to have RewriteRules in .htaccess, IMHO ...
ASKER
Oh, sorry, did not notice it.
So I will paste into httpd.conf, just tell me pls the right syntax for path
So I will paste into httpd.conf, just tell me pls the right syntax for path
RewriteLog "C:/Program Files/Apache Group/Apache2/logs/rewrite .log"
ASKER
This is what I get in rewrite.log file
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) init rewrite engine with requested uri /
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (3) applying pattern '^(.*)$' to uri '/'
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) rewrite / -> http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) explicitly forcing redirect with http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (1) escaping http://www.airport.az// for redirect
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (1) redirect to http://www.airport.az// [REDIRECT/301]
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) init rewrite engine with requested uri /
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (3) applying pattern '^(.*)$' to uri '/'
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) rewrite / -> http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) explicitly forcing redirect with http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (1) escaping http://www.airport.az// for redirect
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (1) redirect to http://www.airport.az// [REDIRECT/301]
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) init rewrite engine with requested uri /
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (3) applying pattern '^(.*)$' to uri '/'
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) rewrite / -> http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) explicitly forcing redirect with http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (1) escaping http://www.airport.az// for redirect
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (1) redirect to http://www.airport.az// [REDIRECT/301]
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) init rewrite engine with requested uri /
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (3) applying pattern '^(.*)$' to uri '/'
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) rewrite / -> http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) explicitly forcing redirect with http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (1) escaping http://www.airport.az// for redirect
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (1) redirect to http://www.airport.az// [REDIRECT/301]
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) init rewrite engine with requested uri /
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (3) applying pattern '^(.*)$' to uri '/'
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) rewrite / -> http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) explicitly forcing redirect with http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (1) escaping http://www.airport.az// for redirect
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (1) redirect to http://www.airport.az// [REDIRECT/301]
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) init rewrite engine with requested uri /
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (3) applying pattern '^(.*)$' to uri '/'
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri d#626a3f8/ initial] (2) rewrite / -> http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][ri
ASKER
Looks like I managed to make it work. I had to change a publishing rule on ISA from www.airport.az to airport.az
Thank you anyway, to rewrite.log file helped me a lot!
Thank you anyway, to rewrite.log file helped me a lot!
glad to have helped, thanks and good luck
AllowOveride All
In the main httpd.conf
On the error you have several rewrites that match, you need to have a request that matches one rule not five.
Start with fewer rules and add one at a time until you get an error and hen determin what it is it you want to achieve ith this redirect.