wheel

msg:1497382 | 5:25 pm on Jan 30, 2006 (gmt 0) |
This is probably more than you need or are looking for, but what I do is set up apache to have the 404 page go to a script. That script then does a lookup in a mysql database that maps the 'pretty' url to the dynamic url. If it finds the pretty url in the database, it issues a 200 page header and then displays the page. If it doesn't, it leaves the 404 and displays an error. That allows me to map pages without any consideration for patterns or regular expressions in the URL's. What it doesn't do is map a dynamic page to another dynamic page.
|
timster

msg:1497383 | 5:49 pm on Jan 30, 2006 (gmt 0) |
A backreference is what you need: RewriteCond %{REQUEST_URI} /page.php$ RewriteCond %{QUERY_STRING} ^q=([0-9]+) RewriteRule ^.*$ /newfolder/page.php?q=%1 [R=301,L]
User Edit -- Added REQUEST_URI condition to make match more specific. [edited by: timster at 6:02 pm (utc) on Jan. 30, 2006]
|
jdMorgan

msg:1497384 | 5:58 pm on Jan 30, 2006 (gmt 0) |
> [...] set up apache to have the 404 page go to a script. Comment/warning only: If you use the 404 error handler method, you need to be absolutely sure that the server response code is correct. You cannot allow the 404 error handler to return a 404-Not Found status for pages that *do* exist. Otherwise, you'll trash your search engine rankings. Use a server headers checker [webmasterworld.com] to be sure... Jim
|
siteseo

msg:1497385 | 7:43 pm on Jan 31, 2006 (gmt 0) |
Thanks for the input. I went with this: RewriteCond %{REQUEST_URI} /page.php$ RewriteCond %{QUERY_STRING} ^q=([0-9]+) RewriteRule ^.*$ /newfolder/page.php?q=%1 [R=301,L] Two questions though: 1. How is %1 different from $1 2. What if I have this in the URL: page.php?q=16+00001 The second line above doesn't seem to work then.
|
jdMorgan

msg:1497386 | 8:34 pm on Jan 31, 2006 (gmt 0) |
Simplifying and correcting the query value problem:
RewriteCond %{QUERY_STRING} ^q=[^&]+ RewriteRule ^page\.ph$ http://www.example.com/newfolder/page.php [R=301,L]
As with the original, the redirect will not occur if the query string is blank or if the parameter is missng. %1 is a back-reference to the first parenthesized value matched in the mosr-recently-matched RewriteCond, whereas $1 is a back-reference to the first parenthesized value matched in the RewriteRule. Neither are required in this case, because query strings are passed through unmodified by default -- unless you have other rules that are interfering. Also, be aware that the redirect will only occur if the query string starts with "q=". The pattern [^&]+ requires one or more characters not equal to an ampersand. This is in case you have other query name/value pairs following the "q=" stuff. Obviously, there are many, many variations possible, so I took my best guess at what you're trying to accomplish. Jim
|
siteseo

msg:1497387 | 10:55 pm on Jan 31, 2006 (gmt 0) |
Thanks for the good feedback. In this case though I have to redirect a specific page to another specific page, so using wildcards will probably get me into trouble. I need help with the 16+0001 part of the URL - are the 16 and the 0001 treated as separate components, or as one string of text in this case? I tried several things, including RewriteCond %{QUERY_STRING} ^q\=16\+0001 but no luck.
|
jdMorgan

msg:1497388 | 11:31 pm on Jan 31, 2006 (gmt 0) |
Try
RewriteCond %{QUERY_STRING} ^q=16\+0001
or
RewriteCond %{QUERY_STRING} ^q=16\%2b0001
The "=" does not need to be escaped. However, the "+" does need to be escaped if it appears as a literal. Additionally, "+" may appear as an encoded entity in the query string, in which case it will match "%2b". I showed both cases, since I'm not sure how it appears inside %{QUERY_STRING} (please let us know!). Jim
|
siteseo

msg:1497389 | 10:19 pm on Feb 1, 2006 (gmt 0) |
Neither RewriteCond %{QUERY_STRING} ^q=16\+0001 or RewriteCond %{QUERY_STRING} ^q=16\%2b0001 worked. I'm at a loss...
|
jdMorgan

msg:1497390 | 10:50 pm on Feb 1, 2006 (gmt 0) |
Let me back up and ask a basic question... Do you have any other working RewriteRules on this server? Unrelated question: Can you post a line from your raw access log showing a request for this specific file? Jim
|
siteseo

msg:1497391 | 12:08 am on Feb 3, 2006 (gmt 0) |
Thanks jdMorgan for your help. This is what finally worked for me: RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /folder/page\.php\?q=16 HTTP/ RewriteRule ^folder/page\.php$ http://www.domain.com/newfolder/page.php?q=16 [R=301,L] [edited by: jdMorgan at 2:20 am (utc) on Feb. 3, 2006] [edit reason] De-linked [/edit]
|
jdMorgan

msg:1497392 | 2:18 am on Feb 3, 2006 (gmt 0) |
The crux of this problem was with the "+" in the query string, so a slightly-more accurate depiction of the solution is:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /folder/page\.php\?q=16\+0001 HTTP/ RewriteRule ^folder/page\.php$ http://www.domain.com/newfolder/page.php?q=16+0001 [R=301,L]
Jim
|
|