[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

mod_rewrite rules not behaving as expected

Posted on 2011-10-17
5
Medium Priority
?
254 Views
Last Modified: 2012-05-12
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.

0
Comment
Question by:doyle007
  • 2
  • 2
5 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 36978700
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>


0
 

Author Comment

by:doyle007
ID: 36978716
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.

0
 
LVL 9

Accepted Solution

by:
pritamdutt earned 1000 total points
ID: 36978895
Hey I checked the site and it seems to be opening correctly.
0
 
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 1000 total points
ID: 36978944
I agree with pritamdutt - I worked for me as well. I did not test the link earlier. Perhaps you have a caching problem.

Try a different browser
0
 

Author Comment

by:doyle007
ID: 36978961
Hey guys,
I did some fiddling around and yes its working normally now.
Thanks guys :)
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month18 days, 5 hours left to enroll

830 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