Forum Moderators: phranque

Message Too Old, No Replies

.htaccess Rewrites

         

BohrMe

3:30 pm on Mar 21, 2005 (gmt 0)

10+ Year Member



I need to redirect traffic from my old links to my new ones. The old values are like this:

modules.php?name=News&file=article&sid=100

and the new links are like this:

?p=100

I thought that this might do it but it doesn't work.

RewriteRule ^modules.php?name=News&file=article&sid=([0-9]*) ?p=$1

In fact, I can't get $1 populated with anything!

If I use this

RewriteRule ^modules.*([0-9]*) [%{HTTP_HOST}...] [NC,R]

$1 is blank.

I noticed that if I leave off [%{HTTP_HOST}...] the full path to my DocumentRoot is appended to the URL. Is there something special about "?p"?

jdMorgan

4:10 pm on Mar 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I noticed that if I leave off [%{HTTP_HOST}...] the full path to my DocumentRoot is appended to the URL.

That's very strange, and hints that some other rewrite (or similar mechanism, possibly at the server level) may be interfering with yours. There's also a chance that your particular code is forcing mod_rewrite through some unexpected software execution path, or that it's "guessing" at what you want and trying to do a fix-up. I don't know.

> Is there something special about "?p"?

Yes and no. (No) There's no reason that it should make your server insert the value of %(DOCUMENT_ROOT}, %{REQUEST_FILENAME}, or %{SCRIPT_FILENAME}.

(Yes) RewriteRule cannot see query strings, because they are not technically part of a URL-path. Rather, they are data to be passed to the resource at the given URL-path. For this reason, you must use RewriteCond to examine the query string and back-reference it. Modifying the code you posted, we get:


RewriteCond %{QUERY_STRING} ^name=News&file=article&sid=([0-9]*)
RewriteRule ^modules\.php$ http://www.example.com/?p=%1 [R=301,L]

Hopefully, the above will get you started down the right path.

Jim

BohrMe

2:12 am on Mar 22, 2005 (gmt 0)

10+ Year Member



Thanks. It worked like a champ. I really appreciate the help!