Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to write a rewrite rule in .htaccess for my php website

My website is v2.example.com and I am trying to write a .htaccess rule but unable.

I want this : v2.example.com/ABCDEFGH

And I want to get the value ABCDEFGH as a parameter like it is v2.example.com/index.php?id=ABCDEFGH

can anyone please help me sorting out this problem.

I tried this :

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

Please help me.

like image 276
Dead Man Avatar asked Nov 02 '22 06:11

Dead Man


1 Answers

Have your rule like this:

<IfModule mod_rewrite.c>
RewriteEngine On 
RewriteBase /

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+index\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?id=$1 [L,QSA]
</IfModule>
like image 77
anubhava Avatar answered Nov 15 '22 04:11

anubhava