mod_rewrite simple question

Hi there,

This is currently what I am working with:

Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^index\\.php?act=rssout&id=([0-9]*)$ index.php/rss/forums/$1 [R=301,L]

I want

index.php?act=rssout&id=1 to go to index.php/rss/forums/1

permanently. The code above isn’t working. No errors, no redirect, nothing. I am not sure what is going wrong here…

I appreciate the help… you guys are great.

The rewrite rule only matches against the request URI, not the query string. I believe you’ll need a RewriteCond on the query string to match against that in addition to the RewriteRule

RewriteCond %{QUERY_STRING} pattern
RewriteRule …


… and what’s with the RewriteBase / directive, too!

Best to have ANOTHER look at the tutorial in my signature.



Out of all the multiple languages I know, this is the most hard. I appreciate your patience. :slight_smile:

As I have been “studying,” this is what I have come up with:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^act=rssout&id=([0-9])$
RewriteRule ^index.php$ index.php/rss/forums/%1 [L]

But it isn’t changing anything… I’m not asking you to necessarily solve my problem, but could you point me in the right direction for me to discover what is wrong? :wink:

Thank you so much!

Just to make sure, you are typing to test this, right?

Some people get confused and think mod_rewrite works in reverse.

Your pattern and rule are correct and do work. I suspect you want the URL in the address bar to change – in that case, you need to specify a redirect header rather than just a rewrite, by adding a flag:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^act=rssout&id=([0-9])$
RewriteRule ^index.php$ index.php/rss/forums/%1 [L,R=301]

Regular expressions do take a bit of practice to wrap your mind around. I avoided them at first. I wish I hadn’t, because they’re useful all over the place now.


It looks like you’ve got it EXCEPT that your id is likely more than a single digit (in which case, you need to add the + metacharacter after the ] in the regex) like:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^act=rssout&id=([0-9][COLOR="Red"]+[/COLOR])$
RewriteRule ^index.php$ index.php/rss/forums/%1[COLOR="DeepSkyBlue"]?[/COLOR] [L]

Note: This redirect also REQUIRES that index.php be the requested file.

Using MultiViews (an UGLY thing to do, IMHO), you’re also taking the chance that mod_rewrite will lop off the subdirectory portion of the URI (I don’t know whether it does that or not) and provide you with a loop BECAUSE you did not kill the query string (blue ?).

TIP: To see whether the redirection is working or not, change the [L] flag to [R=301,L] but don’t forget to change back when you’re satisfied that it’s working properly.



Thank you so much for your help – I have got it working correctly now. :slight_smile:

I really appreciate it. I think I am getting the hang of this now.


:eek2: That makes you dangerous!

Be careful as this regex stuff is very powerful!