same file, server and htaccess, different domain = problem

Oh, the strange things mod_rewrite does!

same file, server and htaccess, different domain = problem

Postby lucadg » Sun May 25, 2008 11:46 pm

Hello all,
I am using this rule in the root htaccess

Code: Select all
RewriteRule ^.([^/]*)-apartments\.html$ /ap/index.php?cityid=$1 [L]


to rewrite
http://www.apartmentoski.com/Riga-apartments.html
to
http://www.apartmentoski.com/ap/index.php?cityid=Riga
it works perfectly, as all the other rules work perfectly all over the site.

But...
I have another domain: http://www.myapartments.eu
it points to the same server and folder and as a consequence uses the same .htaccess.
(in case you wonder why I have 2 domains, this one shows different cities, but this does not matter here)

but, as you can see in
http://www.myapartments.eu/Riga-apartments.html
there is a problem with the city name which looses the first letter.

The variable
Code: Select all
$cityname = $_GET['cityid'];

used in the page, which gets the city name from
http://www.myapartments.eu/ap/index.php?cityid=Riga

is actually getting it from
http://www.myapartments.eu/ap/index.php?cityid=iga

See Riga, becomes iga
(and so with all cities)

Now, changing the rewrite rule makes it work in myapartments.eu and generates an error in apartmentoski.com .
There seem to be no rule able to satisfy both domain names.

Also with other domains such as
http://www.mykrakowapartments.com/riga-apartments.html
it does not work.

the only difference is the domain name

Can anybody point me in the right direction?
I could use a php function to rewrite the wrong variable but it would not be elegant!

Thanks!

Luca
lucadg
 
Posts: 17
Joined: Sun May 25, 2008 11:29 pm

Postby richardk » Wed May 28, 2008 2:11 pm

Try
Code: Select all
^([^/]*)-apartments\.html$

or
Code: Select all
^/?([^/]*)-apartments\.html$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby lucadg » Thu May 29, 2008 1:02 am

^([^/]*)-apartments\.html$

in http://www.apartmentoski.com/Riga-apartments.html : page not found
in
http://www.myapartments.eu/Riga-apartments.html : works
^/?([^/]*)-apartments\.html$

works with both!

Great, thank you Richard!

So, what is the reason for this different behavior with different domains?
lucadg
 
Posts: 17
Joined: Sun May 25, 2008 11:29 pm

Postby richardk » Sun Jun 01, 2008 10:17 am

It must be the way they are configured, but i don't know what exactly would cause this. Normally you need the leading slash in <VirtualHost>s and the main server configuration and not in .htaccess files or <Directory>s. But as it is using the same .htaccess file i don't know what the cause is.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 5 guests

cron