?
Solved

mod_rewrite Apache Windows Server

Posted on 2012-04-10
18
Medium Priority
?
473 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
  • 3
18 Comments
 
LVL 79

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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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 79

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 79

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
 
LVL 18

Author Comment

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

Accepted Solution

by:
ahoffmann earned 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

801 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