.htaccess remove index.php and hide parameter key from urls

I have the following URL

www.example.com/index.php?tag= xxx 

I want to do it like this: .htaccess

 www.example.com/xxx 

I did this with this code:

  Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.+?)/?$ /index.php?tag=$1 [L,QSA] 

SO if I enter this url:

 www.example.com/index.php?tag=1000 

it will be redirected to:

 www.example.com/?tag=1000 

if: www.example.com/1000 it works!

So, I have a dublicate URL, and that is not good for seo.

How to redirect www.example.com/index.php?tag=1000 to www.example.com/1000

+5
source share
2 answers

How to redirect www.example.com/index.php?tag=1000 to www.example.com/1000

You can insert this rule just below the RewriteBase line:

 RewriteCond %{THE_REQUEST} /(?:index\.php)?\?tag=([^\s&]+) [NC] RewriteRule ^ /%1? [R=302,L,NE] 
0
source

use this code for the .htaccess file

 Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.+?)/?$ /index.php?key=$1 [L,QSA] 

code index.php will be

 <?php echo $_REQUEST['key']; ?> 

then call http://sitename.com/1000

: 1000

0
source

All Articles