Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite

mod_rewrite, folder, restrictions

         

mhamdi

3:38 am on Nov 24, 2006 (gmt 0)

10+ Year Member



Hi guys,
I need to make few changes in my .htaccess file but I am lost in all the mod_rewrite examples. please help!
What I need is the following:
1: redirect all traffic coming to ./folder/filename to ./filename
2. I have the following rule:
RewriteRule ^(.*)?/?files/(.*) wp-content/blogs.php?file=$2 [L]
It works fine but I have a gallery where the images are stored in a subfolder called files as well: ./gallery/files/ and isthen affected by the above rule. How can I restrict it to all but gallery/files/....

Thanks a lot!

jdMorgan

4:02 am on Nov 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since you want to make your rule conditional upon NOT(URL=/gallery/files/<anything>), you need a RewriteCond directive. Something like:

RewriteCond %{REQUEST_URI} !^/gallery/files/
RewriteRule ^([^/]+/)*files/(.*)$ wp-content/blogs.php?file=$2 [L]

(Also a minor tweak to your initial rule pattern for improved efficiency.)

Be aware that since it is the client (e.g. browser) that resolves relative links, and since the browser is not aware that you have rewritten the URLs, you may have some trouble with page-relative links to images, CSS, included external JavaScript files, etc. If so, use server-relative links or canonical links on your pages instead, i.e. use <img src="/images/logo.gif"> or <img src="http://example.com/images/logo.gif">, instead of <img src="images/logo.gif"> or <img src="../images/logo.gif">

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

mhamdi

6:53 am on Nov 26, 2006 (gmt 0)

10+ Year Member



Thanks a lot jdMorgan, the 2nd rule works great, I still need another rule to redirect [domain.com...] to [domain.com...] Can you please help me with that.