Help doing multiple rewrites

Discuss practical ways rearrange URLs using mod_rewrite.

Help doing multiple rewrites

Postby sebjt » Sat May 24, 2008 6:06 am

Hi Guys,

I need to have an .htaccess that changes

http://www.mydomain.com/value/ to http://www.mydomain.com/?s=value

http://www.mydomain.com/value/value/ to
http://www.mydomain.com/?s=value&p=value

http://www.mydomain.com/value/value/value/value/ to http://www.mydomain.com/?s=value&p=valu ... ue&n=value

however needs to ignore /css/ /images/ /js/ /videos/ /assets/

I have started with this:

Options +FollowSymLinks
RewriteEngine on
rewriteCond %{REQUEST_URI} !^/assets/
rewriteCond %{REQUEST_URI} !^/js/
rewriteCond %{REQUEST_URI} !^/images/
rewriteCond %{REQUEST_URI} !^/css/
rewriteCond %{REQUEST_URI} !^/videos/

RewriteCond %{DOCUMENT_ROOT}/([^/]+)/ -f
RewriteRule ([^/]+)/?$ /?s=$1 [L]

RewriteCond %{DOCUMENT_ROOT}/([^/]+)/([^/]+)/ -f
rewriteRule ([^/]+)/([^/]+)/?$ /?s=$1&p=$2 [L]

RewriteCond %{DOCUMENT_ROOT}/([^/]+)/([^/]+)/([^/]+)/([^/]+)/ -f
rewriteRule ([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /?s=$1&p=$2&v=$3&n=$4 [L]

but it doesn't quite work

Thanks in advance,

Seb
sebjt
 
Posts: 1
Joined: Sat May 24, 2008 5:58 am

Postby richardk » Sun May 25, 2008 10:23 am

[/code]RewriteCond %{DOCUMENT_ROOT}/([^/]+)/ -f[/code]

You're checking if it's a file, but /value/ is not.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Ignore these directories.
RewriteRule !^(assets|css|images|js|videos)(/.*)?$ - [NC,L]

# Match up to four parts.
RewriteRule ^([^/]+)(?:/([^/]+)(?:/([^/]+)(?:/([^/]+))?)?)?/?$ /?s=$1&p=$2&v=$3&n=$4 [QSA,L]
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 16 guests

cron