rewrite conditions

Discuss practical ways rearrange URLs using mod_rewrite.

rewrite conditions

Postby kevindoyleie » Fri Oct 03, 2008 2:29 am

Hi

I'm working on a branded version of a site with won't have all the functionality of the original so I have written a rewrite condition to redirect users if they enter a url that isn't allowed.

RewriteCond %{REQUEST_URI} !^/search/webhome [NC]
RewriteCond %{REQUEST_URI} !^/search/search [NC]
RewriteCond %{REQUEST_URI} !^/search/redir [NC]
RewriteCond %{REQUEST_URI} !^/search/help [NC]
RewriteCond %{REQUEST_URI} !^/search/about [NC]
RewriteCond %{REQUEST_URI} !^/search/weboffers [NC]
RewriteCond %{REQUEST_URI} !^/search/afe [NC]
RewriteRule ^/(.*) http://[url]/search/webhome [L,R=301]

Which works.
The problem is that it isn't allowing any assets like images to be displayed.
What do I need to add to my condition to get the assets to display?
They will live in a directory called assets and there will be many sub-directories off that.

Many thanks for any feedback.

K
kevindoyleie
 
Posts: 1
Joined: Fri Oct 03, 2008 2:24 am

Postby richardk » Fri Oct 03, 2008 10:38 am

You have to add exceptions for them too.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Ignore a directory containing your assets.
RewriteCond %{REQUEST_URI} !^/assets(/.*)?$ [NC]
# Ignore a specific file.
RewriteCond %{REQUEST_URI} !^/asset\.ext$ [NC]
RewriteRule !^/search/(webhome|search|redir|help|about|weboffers|afe)$ http://[url]/search/webhome [R=301,L]


Or, you might be able to use
Code: Select all
RewriteCond %{SCRIPT_FILENAME} !-f

instead of
Code: Select all
# Ignore a directory containing your assets.
RewriteCond %{REQUEST_URI} !^/assets(/.*)?$ [NC]
# Ignore a specific file.
RewriteCond %{REQUEST_URI} !^/asset\.ext$ [NC]

so it allows access to all your existing files (it depends on whether that will allow URLs you don't want).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 13 guests

cron