Jump to content

Help with a rewrite rule


Alex

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/197588-help-with-a-rewrite-rule/
Share on other sites

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?

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 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.