Simple htaccess question

I need a little help with rewrite rule.

I have the following two rules for index.php:
RewriteCond %{THE_REQUEST} [1]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://localhost/ [R=301,L]

Now I would like to get a value of $_GET[show] from index.php?show=topUsers which is from http://localhost/topUsers

I tried the following, but it doesn’t work:
RewriteRule ^/$ /index.php?show=$1 [L]

I hope anybody can help me with this.

tnx


  1. A-Z ↩︎

thank you for your response. I will simply use RewriteRule ^topUsers$ index.php?show=topUsers [L].

I am not sure why I used RewriteCond %{THE_REQUEST} [1]{3,9}\ /index\.php\ HTTP/, I copied it long time ago from one of tutorial, maybe for some seo purposes. My DirectoryIndex is index.php (index.php is in main directory).

So I can simply delete this line and leave the following:

RewriteEngine on
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]
RewriteCond %{HTTP_HOST} ^domainname.com [NC]
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]
RewriteRule ^index\.php$ http://www.domainname.com/ [R=301,L]
RewriteRule ^topUsers$ index.php?show=topUsers [L]


  1. A-Z ↩︎

e1a,

WHAT?

Q1. WHY use %{THE_REQUEST} for anything? Its format is so incredibly useless to mod_rewrite that I NEVER use it - {REQUEST_URI} is the basic variable that you should be using.

Q2. What is your DirectoryIndex? If it’s index.php and you’re directing to / which resolves to index.php, it SHOULD put you in a tailchase (LOOPY) mode!

Q3. WHICH way are you going? If /topUsers => index.php?show=topUsers, then that’s pretty simple:

RewriteRule ^topUsers$ index.php?show=topUsers [L]

Otherwise, you’re going from a request that Apache can serve to one Apache can’t: index.php?show=topUsers => topUsers. Of course, that CAN be done with:

RewriteCond %{QUERY_STRING} show=topUsers&?
RewriteRule index\\.php topUsers [L]

But WHY?

Of course not! The $1 variable must be created to be used. IMHO, a quick look at the regex section then the sample codes of my signature’s tutorial may be of great assistance to you.

Regards,

DK