Solved

mod_rewrite Apache Windows Server

Posted on 2012-04-10
18
451 Views
Last Modified: 2012-04-12
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!
0
Comment
Question by:fgasimzade
  • 8
  • 7
  • 3
18 Comments
 
LVL 76

Expert Comment

by:arnold
ID: 37830838
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37831638
you're missing:

RewriteCond %{HTTP_HOST} !^www\.airport\.az$
0
 
LVL 18

Author Comment

by:fgasimzade
ID: 37831891
@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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37831921
> ... the result is the same.
then please check your logfiles, it should contain hints about the redirects
post relevant messages if unsure
0
 
LVL 18

Author Comment

by:fgasimzade
ID: 37832961
Where can I find the logfiles?
0
 
LVL 76

Expert Comment

by:arnold
ID: 37833860
look where your httpd.conf file within it there should be a reference to logfile location
likely where apache is installed \logs
0
 
LVL 18

Author Comment

by:fgasimzade
ID: 37836062
I found access logs and error logs but there is nothing there regarding redirection, as far as I understand
0
 
LVL 76

Expert Comment

by:arnold
ID: 37836223
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37836245
> 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 18

Author Comment

by:fgasimzade
ID: 37836292
@ahoffmann, Yes, they are..
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 37836377
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
 
LVL 18

Author Comment

by:fgasimzade
ID: 37836692
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37836714
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
 
LVL 18

Author Comment

by:fgasimzade
ID: 37836754
Oh, sorry, did not notice it.

So I will paste into httpd.conf, just tell me pls the right syntax for path
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37836760
RewriteLog "C:/Program Files/Apache Group/Apache2/logs/rewrite.log"
0
 
LVL 18

Author Comment

by:fgasimzade
ID: 37836767
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
 
LVL 18

Author Comment

by:fgasimzade
ID: 37836802
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37836811
glad to have helped, thanks and good luck
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now