How to manipulate the URL with .htaccess for certain links


How can I manipulate the url by using .htaccess to make the url below work and shorten the size?

I successfully removed the .php, .html extension from the url, but don’t have a clue on how to manipulate the character positions and remove the query variable name.


RewriteEngine On
DirectoryIndex index.php

ErrorDocument 404 /public_html/404.php
ErrorDocument 500 /public_html/500.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]

>Solution :

With your shown samples, please try following htaccess rules file. Please make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
##External redirect 301.
RewriteCond %{THE_REQUEST} \s/(blog)\?language=(\S+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Internal rewrite to index.php file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/(.*)/?$ index.php?param1=$1&language=$2 [QSA,NC,L]

Leave a Reply Cancel reply