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!
LVL 18
fgasimzadeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
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.
0
ahoffmannCommented:
you're missing:

RewriteCond %{HTTP_HOST} !^www\.airport\.az$
0
fgasimzadeAuthor Commented:
@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>
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

ahoffmannCommented:
> ... the result is the same.
then please check your logfiles, it should contain hints about the redirects
post relevant messages if unsure
0
fgasimzadeAuthor Commented:
Where can I find the logfiles?
0
arnoldCommented:
look where your httpd.conf file within it there should be a reference to logfile location
likely where apache is installed \logs
0
fgasimzadeAuthor Commented:
I found access logs and error logs but there is nothing there regarding redirection, as far as I understand
0
arnoldCommented:
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.
0
ahoffmannCommented:
> 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?
0
fgasimzadeAuthor Commented:
@ahoffmann, Yes, they are..
0
ahoffmannCommented:
please insert following in your httpd.conf

RewriteEngine on
RewriteLog /path/to/your/rewrite.log
RewriteLogLevel 3
RewriteCond %{HTTP_HOST} !^www\.airport\.az$
.... your other, existing, Rewrite* directives here ....

then try a URL which should be redirected
if it does not redirect as expected, please post
  1. the URL you used in the browser
  2. the redirected URL (if any) you see in the browser
  3. content of /path/to/your/rewrite.log according request (see 1.)
  4. check your acess.log and error.log for relevant messages and post them
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fgasimzadeAuthor Commented:
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
0
ahoffmannCommented:
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 ...
0
fgasimzadeAuthor Commented:
Oh, sorry, did not notice it.

So I will paste into httpd.conf, just tell me pls the right syntax for path
0
ahoffmannCommented:
RewriteLog "C:/Program Files/Apache Group/Apache2/logs/rewrite.log"
0
fgasimzadeAuthor Commented:
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//
0
fgasimzadeAuthor Commented:
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!
0
ahoffmannCommented:
glad to have helped, thanks and good luck
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.