Forum Moderators: phranque
RewriteRule ^/(.+)/trackback$ /$1/trackback/ [R]
RewriteRule ^/(.+)/trackback/$ /$1/ [R=301,L]
The other URL I want to rewrite is this one:
http://www.example.com/?q=samplequery
What I want to do with that one is just return a 404.I couldnīt find any redirection rule for a 404.
Finally, here is my .htaccess file so you guys can see what might be wrong.Maybe thereīs another rule that prevents the ones Iīm trying from working:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]
RewriteRule ^/(.+)/trackback$ /$1/trackback/ [R]
RewriteRule ^/(.+)/trackback/$ /$1/ [R=301,L]</IfModule>
I would not worry about handling the trailing slash for the trackback. Also, because of the placement of your rules below the all-inclusive rules provided by Wordpress, your rules are never even being checked. The page request for "/whatever/trackback" was already matched and rewritten by the "RewriteRule . /index.php [L]" line.
Here's an idea of how it should be structured to achieve your goal (untested):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/([^/]+)/trackback /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^([^/]+)/trackback /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteRule ^([^/]+)/?q=([^/]+)$ [R=404]
I remember reading on the Apache website about mod_rewrite that R is used for returning the 300-400 codes,but I havent read on any other way how to do this.
Instead, simply rewrite to a filepath that does not exist.
To catch query strings, you'll need to use a RewriteCond with the %{QUERY_STRING} variable.
Try a search [webmasterworld.com] on WebmasterWorld to find lots of previous threads.
Jim
[edited by: jdMorgan at 2:21 am (utc) on Nov. 4, 2006]