Forum Moderators: phranque
First problem:
When someone goes to http://domain.com/index.php?p=200&more=1 they are not getting a 404. They are going to http://domain.com/ I have not set up any redirects for that.
Second problem:
I need to redirect http://domain.com/index.php?p=200&more=1 to http://domain.com/archives/200.php I haven't found any way that works correctly. The forward I was trying to use kept forwarding http://domain.com/index.php to http://domain.com/archives/200.php
RewriteRule for "example.com/?searchstring" [webmasterworld.com]
/claus
Welcome to WebmasterWorld [webmasterworld.com]!
The code you reviewed had a problem --- posting on this board removed the required spaces preceding the "!" character in that post. Based on your trouble, I have edited that post to correct the problem.
The following sample should get you a bit closer: This does an external redirect to meet the requirements you posted. However you may not want an external redirect. This code is intended for use in .htaccess and won't work properly in httpd.conf. Also, it only handles the one specific case you posted, not the general case of "p=n" redirecting to "archives/n.php" -- again, it wasn't clear if you wanted a general or specific solution.
We try not to "write your code for you" here (see the Charter link above), but this should get you going in the right direction. Specific questions about problems with your code are welcome.
RewriteCond %{QUERY_STRING} ^p=200&more=1$
RewriteRule ^index\.php$ http://www.example.com/archives/200.php [R=301,L]
Jim
RewriteEngine On
RewriteCond %{QUERY_STRING} ^p=78598894&more=1$ [NC]
RewriteRule ^index.php$ http://www.domain.com/archives/000124.php? [R,L] I don't understand why when someone goes to [domain.com...] they don't get a 404.
You won't get a 404 if index.php exists. The query string (everything following the "?") is *not* part of the resource name, it is a query to be passed to that resource. Therefore, the 404 test does not look at the query string at all -- If the index.php file exists, no 404.
The query string is handled separately, as further evidenced by the fact that you have to test it separately in the rewrite code using RewriteCond.
Try adding "Options +FollowSymLinks" ahead of "RewriteEngine on". If that doesn't work, have a look at your error log file to see if it says anything.
Jim
In Unix, *nix, and Apache -- and especially in mod_rewrite -- capitalization matters a lot. Forget 'personal coding style,' and do it exactly like it shows in the book [httpd.apache.org].
Also, be careful with that [NC] flag - too often, people use it 'by habit' and get into trouble. If your query string is generated as part of the output for a previously-visited page, then there's no reason to make the pattern-match case-insensitive since your script will never generate any uppercase variants.
With mod_rewrite, it's all in the details.
Glad you got it working!
Jim