Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite question

cannot get mod_rewrite to work

         

macaco

9:10 pm on Aug 3, 2008 (gmt 0)

10+ Year Member



I'd like to redirect URLs in a directory in this way:

categories/anything/index.php?id=13 to
categories/index.php?id=13

To achieve that, I've uploaded a .htaccess file to "categories" directory that contains the following:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^[.*]/index\.php\?id=([0-9]*)$ index.php?id=$1
</IfModule>

But it keeps giving a 500 error

How do I fix this?

Many Thanks

jdMorgan

11:09 pm on Aug 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The following may be sufficient, since "/" is the default RewriteBase, and query strings are passed through by default:

RewriteEngine on
RewriteRule ^[^/]+/index\.php$ /categories/index.php [L]

If you wish to require that the query string contain "id=<number>", then you'll need one more line:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=[0-9]+$
RewriteRule ^[^/]+/index\.php$ /categories/index.php [L]

Query strings are not visible to RewriteRule, and must be handled separately using a RewriteCond as shown.

If you still get a 500-Server Error, take a look at your server error log file -- It will often tell you exactly what is wrong. The most likely cause would be that your server config requires you to add

 Options +FollowSymLinks 
above this code snippet -- But don't add that unless it's required.

Jim

macaco

11:42 pm on Aug 3, 2008 (gmt 0)

10+ Year Member



Great, worked perfectly.

Many Thanks for your explanation, Jim!