Link to home
Start Free TrialLog in
Avatar of doyle007
doyle007

asked on

mod_rewrite rules not behaving as expected

Hi all,
I'm running an apache2 webserver with virtual hosting.
my sites are behaving strangely.

I have 2 sites
autohunter.com.au
halalhunter.com.au

everything on autohunter.com.au behaves as I want.
however halalhunter.com.au is doing something strange. when i go to halalhunter.com.au it goes to the right page,
When I go to www.halalhunter.com.au it goes to www.autohunter.com.au 

When i use the http://www.halalhunter.com.au it goes to www.autohunter
and when I use http://halalhunter.com.au it goes to halalhunter.com.au as expected...

So basically anytime i use www with halalhunter it goes to the wrong site...

here are my .htaccess files

AUTOHUNTER :
Options +FollowSymLinks

# Error Files
ErrorDocument 400 /errors/400.html
ErrorDocument 401 /errors/401.html
ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /var/www/autohunter.com.au/

RewriteCond %{HTTP_HOST} !^www.autohunter.com.au$ [NC]
RewriteRule ^(.*)$ http://www.autohunter.com.au/$1 [R=301,L]
RewriteRule ^(search.php)/(.*)/(.*)/(.*)$ http://www.autohunter.com.au/$1 [R=301,L]


RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule

Open in new window

>

and here is Halalhunter.com.au
Options +FollowSymLinks

# Error Files
ErrorDocument 400 /errors/400.html
ErrorDocument 401 /errors/401.html
ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.halalhunter\.com\.au$ [NC]
RewriteRule ^\/?(.*?)$ http://halalhunter.com.au/$1 [R=301,L]

</IfModule>

Open in new window


I would be most grateful if anyone can help, and also tell me if there is something else I am doing wrong with the config above. I can provide more config settings if needed.
Cheers.

Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Another possibility is the virtualhost definitions in your webserver. I am assuming this is a webserver you have set up rather than two you are renting.

If these are specified incorrectly then all traffic may wind up going to a default server - usually the first one set up. Your virtualhost definitions should look like

<VirtualHost 11.22.33.44>
ServerName halalhunter.com.au
ServerAlias www.halalhunter.com.au
... other stuff...
</VirtualHost>

<VirtualHost 11.22.33.44>
ServerName autohunter.com.au
ServerAlias www.autohunter.com.au
... other stuff...
</VirtualHost>


Avatar of doyle007
doyle007

ASKER

I was thinking that may be setup wrong....can you see anything bizzare here..
Here is my virtual hosts file (each site has a seperate file...
for halalhunter.com.au

<VirtualHost *:80>
	ServerName halalhunter.com.au
	ServerAlias www.halahunter.com.au
	ServerAdmin blah@blah.com
        DocumentRoot /var/www/halalhunter.com.au


ErrorLog /var/log/halalhunter/error.log
RewriteLog /var/log/halalhunter/rewrite.log
RewriteLogLevel 9

<Directory />
	Order Deny,Allow
	Allowoverride All
</Directory>

<Directory /var/www/halalhunter.com.au>
		Options FollowSymLinks
		Order Deny,Allow
		AllowOverride All
	</Directory>
</VirtualHost>  

Open in new window


and here is the one for Autohunter..

<VirtualHost *:80>
	ServerName autohunter.com.au
	ServerAlias www.autohunter.com.au
	ServerAdmin sam.abdelhamid@gmail.com
        DocumentRoot /var/www/autohunter.com.au

ErrorLog /var/log/autohunter/error.log
RewriteLog /var/log/autohunter/rewrite.log
RewriteLogLevel 9

<Directory />
	Order Deny,Allow
	Allowoverride All
</Directory>

<Directory /var/www/autohunter.com.au>
		Options FollowSymLinks
		Order Deny,Allow
		AllowOverride All
	</Directory>

</VirtualHost>  

Open in new window


There is also a Default one...which is enabled...this is the contents..


<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	
	DocumentRoot /var/www
	<Directory />
		Options FollowSymLinks
		AllowOverride None
	</Directory>
	<Directory /var/www>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all
		# This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
                #RedirectMatch ^/$ /apache2-default/
	</Directory>

	ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
	<Directory "/usr/lib/cgi-bin">
		AllowOverride None
		Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
		Order allow,deny
		Allow from all
	</Directory>

	ErrorLog /var/log/apache2/error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn

	CustomLog /var/log/apache2/access.log combined
	ServerSignature On

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

Open in new window


Really stumped on this one...been trying for a few hours to find the needle in the haystack.

ASKER CERTIFIED SOLUTION
Avatar of pritamdutt
pritamdutt
Flag of India 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
SOLUTION
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
Hey guys,
I did some fiddling around and yes its working normally now.
Thanks guys :)