Alex Posted April 5, 2010 Share Posted April 5, 2010 I'm trying to rewrite something like: file.php?var=val&var2=val2... to: file/var/val/var2/val2... I'm also using the rewrite rule below to redirect site.com to www.site.com. I've tried a few things, but I can't seem to get it working correctly. RewriteEngine On RewriteCond %{HTTP_HOST} !^www.rakugumi.com$ RewriteRule ^(.*)$ http://www.rakugumi.com/$1 [R=301] Quote Link to comment Share on other sites More sharing options...
premiso Posted April 5, 2010 Share Posted April 5, 2010 RewriteEngine On RewriteCond %{HTTP_HOST} ^rakugumi.com RewriteRule ^(.*)$ http://www.rekugumi.com/$1 [R=permanent,L] RewriteRule file/(.*)/(.*)/(.*)/(.*) file.php?$1=$2&$3=$4 [L] Given that I did not make any mistakes the above should work. Quote Link to comment Share on other sites More sharing options...
Alex Posted April 5, 2010 Author Share Posted April 5, 2010 Well, that kind of works. It's too strict, I don't want it to be a requirement that both variables names and values must be there. Just that optionally, up to 2 can be displayed. Also, using this method breaks all relative links, in a case like this would it just be standard to make everything utilize absolute paths? Quote Link to comment Share on other sites More sharing options...
cags Posted April 5, 2010 Share Posted April 5, 2010 It's not really possible in the manner you want. You'd probably have to do a 'catch all' pattern, that simply forwards all pages to it an parses the REQUEST_URI to calculate what exactly to display (similar to how you were doing it originally). It screws up your links because they are no longer relative in position, when working with mod_rewrite you will ideally get used to using static absolute paths. Also bare in mind that any URI on your site that matches the pattern you use will be forwarded there. You probably want to make use of the RewriteConds that check if a file exists before forwarding them. RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.