Semi-recursive rewrite rule..

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

Semi-recursive rewrite rule..

Postby fastly » Wed Jan 12, 2005 4:02 pm

I've been looking to do something a little more complicated with mod_rewrite: ... aramx/valx

should translate to: ... aramx=valx

So basically, we are always translating the first two 'fake' directories into the module and actions, and handling the rest of the 'fake' directories recursively to generate param/val querystring pairs...

Am I completely barking mad, or is this possilbe???

Also, would there by any implications when using relative paths to request images or css markup etc??

Apologies if this has already been answered elsewhere, but if any mod_rewrite experts out there, your advice would be greatly appreciated and I'll let you guys know if I get anywhere!



Postby Caterham » Thu Jan 13, 2005 12:01 am

.htaccess in doc root
Code: Select all
RewriteEngine On

# to avoid problems with exsisting files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]

# rewrite broken relative image paths
RewriteRule ^.+(images|scripts|files)/(.*)$ /$1/$2 [L]

RewriteRule !^ind/? - [C]
RewriteRule ^([^/]+)/([^/]+)/(.*) /ind/$3?module=$1&action=$2

RewriteRule ^ind/([^/]+)/([^/]+)(.*)$ /ind$3?$1=$2 [QSA,N]
RewriteRule ^ind/?$ /index.php [QSA,L]
Indeed, you've to change all relative links so absolute ones or you use mod_rewrite to rewrite the links, see within the code :-)

Note: if you are running apache >1.3.28 or >2.0.45 with more than 9 name-value pairs (variables), you might have to use
Code: Select all
RewriteOptions MaxRedirects=25
in your .htaccess to increase the maximum number of redirects from the default value 10 to 25 (these are so called internal redirects)

Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 17 guests