Link to home
Start Free TrialLog in
Avatar of fgasimzade
fgasimzadeFlag for Azerbaijan

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&start=$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!
Avatar of arnold
arnold
Flag of United States of America image

Check the main configuration to make sure you did not lockout the .htaccess override.
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.
you're missing:

RewriteCond %{HTTP_HOST} !^www\.airport\.az$
Avatar of fgasimzade

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>
> ... the result is the same.
then please check your logfiles, it should contain hints about the redirects
post relevant messages if unsure
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
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.
> 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?
@ahoffmann, Yes, they are..
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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/.htaccess: RewriteLog not allowed here
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 ...
Oh, sorry, did not notice it.

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"
This is what I get in rewrite.log file

85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][rid#626a3f8/initial] (2) init rewrite engine with requested uri /
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][rid#626a3f8/initial] (3) applying pattern '^(.*)$' to uri '/'
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][rid#626a3f8/initial] (2) rewrite / -> http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][rid#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][rid#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][rid#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][rid#626a3f8/initial] (2) init rewrite engine with requested uri /
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][rid#626a3f8/initial] (3) applying pattern '^(.*)$' to uri '/'
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][rid#626a3f8/initial] (2) rewrite / -> http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:06 +0500] [airport.az/sid#5ca500][rid#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][rid#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][rid#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][rid#626a3f8/initial] (2) init rewrite engine with requested uri /
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][rid#626a3f8/initial] (3) applying pattern '^(.*)$' to uri '/'
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][rid#626a3f8/initial] (2) rewrite / -> http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][rid#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][rid#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][rid#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][rid#626a3f8/initial] (2) init rewrite engine with requested uri /
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][rid#626a3f8/initial] (3) applying pattern '^(.*)$' to uri '/'
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][rid#626a3f8/initial] (2) rewrite / -> http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][rid#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][rid#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][rid#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][rid#626a3f8/initial] (2) init rewrite engine with requested uri /
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][rid#626a3f8/initial] (3) applying pattern '^(.*)$' to uri '/'
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][rid#626a3f8/initial] (2) rewrite / -> http://www.airport.az//
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][rid#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][rid#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][rid#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][rid#626a3f8/initial] (2) init rewrite engine with requested uri /
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][rid#626a3f8/initial] (3) applying pattern '^(.*)$' to uri '/'
85.132.43.8 - - [12/Apr/2012:14:47:11 +0500] [airport.az/sid#5ca500][rid#626a3f8/initial] (2) rewrite / -> http://www.airport.az//
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!
glad to have helped, thanks and good luck