Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

Example:
www.website.com/blog?language=en-us
to:
www.website.com/en-us/blog

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]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading