Forum Moderators: phranque
redirect:
http://www.example.com/file.php?x=123
to:
http://www.example.com/file/123
Here's what I'm trying:
RewriteCond %{QUERY_STRING} x=(.*)
RewriteRule ^file.php(.*)$ /file/%1
I have further rules for the framework that I'm using after this:
RewriteCond $1 !^(index\.php¦css¦js¦images¦robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
The reason that I'm doing this is to preserve current links to /file.php?x=123, and have them redirect to the new site that I'm building that will have links of /file/123
I don't really speak this, and this is the only thing I need to do with this, can someone help me?
Your code is for a rewrite. I think you need a redirect if your explanation of what you want to do is correct.
In that case, you'll need to add the domain name to the target URL and the [R=301,L] flags.
If you are trying to achieve "search engine friendly URLs," there are three steps:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /file\.php\?x=([^\ ]*)\ HTTP/
RewriteRule ^file\.php$ http://www.example.com/file/%1? [R=301,L]
GET /file.php?x=123 HTTP/1.1
Using this additional RewriteCond check prevents this rule from redirecting requests which have just been internally rewritten to the "file.php?x=123" form by your other rule, and so avoids a loop.
Jim
[edit] Corrected as noted below. [/edit]
[edited by: jdMorgan at 2:59 am (utc) on June 26, 2009]
I tried this and it works.... only little problems that a real brain could figure out...
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /\?p=([^\ ]*)\ HTTP/
RewriteRule ^$ [domain.com...] [R=301,L]
The only problem is it doesnt have the .html to the end. just leaves it in directory structure.
Next thing I realized after.
Most of them are ?p=blah then I noticed that SOME had ?p=blah&town=bla_g sometimes theres and underscore sometimes there isn't.
Any idea's?