Home > Blockchain >  .Htaccess URL Rewriting - Clean URLs not working using .htaccess
.Htaccess URL Rewriting - Clean URLs not working using .htaccess

Time:01-04

Hi I want to rewrite below URL https://example.com/item?id=223 to https://example.com/google/223. Here ID will be dynamically generated

I have tried this but it is not working

RewriteRule ^google/$ item?id=$1    [R=301,L] 

Any help would be highly appreciated?

CodePudding user response:

With your shown attempts, please try following htaccess rules. Please make sure that your htaccess rules file and your index.php files are present in same folder.

Please make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
##External redirect in browser to new URL.
RewriteCond %{THE_REQUEST} \s/item\?id=(\d )\s [NC]
RewriteRule ^ /google/%1? [R=301,L]

##Internal rewrite to index.php in backend server.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^google/(\d )/?$ index.php?id=$1 [QSA,NC,L]
  • Related