mod_rewrite only for certain files

New to mod_rewrite? This is a good place to start.

mod_rewrite only for certain files

Postby Dominik101 » Thu Jul 30, 2009 4:15 pm

Hi,

I can't find answer for this problem.

I have a subdirectory:
www.mydomain.com/cities/
where i have files of type:
Abakan_Hotels.html
Abigail_Hotels.html
Ankara_Hotels.html
etc.

I would like a mod_rewrite that does the work;
www.mydomain.com/Cityname_Hotels.html-->www.mydomain.com/cities/Cityname_Hotels.html

Shortly, i would like the mod_rewrite work only for files ending with _Hotels.html, pulling them from subdirectory "cities", and that in the browser still stays: www.mydomain.com/Cityname_Hotels.html


I tried the following:

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^(.*_Hotels\.html)$ /cities/$1 [L]

but it doesn't work (error 500).
I'm not experienced with mod_rewrite

Any your help will be appreciated.
Dominik101
 
Posts: 3
Joined: Sun Mar 01, 2009 11:30 pm

Postby richardk » Sat Aug 01, 2009 4:24 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^([^/]+_Hotels\.html)$ /cities/$1 [L]

(Your rule matches the /cities/Cityname_Hotels.html request and loops.)
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Dominik101 » Mon Aug 03, 2009 3:13 am

Hi Richard,

Thanks very much for your reply,

I tried your code but unfortunately id didn't work.
Error 404

I finally solved it though and used the following rule.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^([a-zA-Z]+)_Hotels\.html$ /cities/$1_Hotels.html [L]

It's working fine.

Thanks again for your time,
Dominik
Dominik101
 
Posts: 3
Joined: Sun Mar 01, 2009 11:30 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 25 guests

cron