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
Share on other sites

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.

Link to comment
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?

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.