DtyCFx
DtyCFx

Reputation: 61

htaccess rewrite help needed

I was trying to write a rewrite rule, but so far couldn't achieve what I want. my site is in a subdirectory and the htaccess file is in that directory.

What I want is, if I go to http://example.com/site/ or http://example.com/site/index.phpit should rewrite to

http://example.com/site/index.php?key=2

The value of key won't change. It is fixed. I want it to load by default but hide from the url.

What I tried is,

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site/index.php?key=2&$1 [L,QSA]
</IfModule>

it's not working. but if I go to address http://example.com/site/anything then it works.

Can you please help me in this? I don't understand htaccess very well.

Thanks in advance.

Upvotes: 1

Views: 29

Answers (1)

anubhava
anubhava

Reputation: 784918

Have it this way:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/

RewriteRule ^(index\.php)?$ index.php?key=2 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?key=2&$1 [L,QSA]
</IfModule>

Upvotes: 1

Related Questions