Home > Blockchain >  RewriteRule for hiding file extension and change file name
RewriteRule for hiding file extension and change file name

Time:09-17

starting url - example.com/vid.php
wanted url - example.com/video
any help, pls, to write the RewriteRule

RewriteCond %{THE_REQUEST} /vid\.php\s [NC]
RewriteRule ???

CodePudding user response:

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

Also make sure that your vid.php file is present alongside with htaccess rules file.

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/vid\.php\s [NC]
RewriteRule ^ video? [R=301,L]
RewriteRule ^video/? vid.php [NC,L]

CodePudding user response:

You don't even need a separate RequestCond here...

RewriteEngine on
RewriteRule ^/?vid\.php$ /video [QSA,R=301,L]
RewriteRule ^/?video/? /vid.php [QSA,END]

Test with a fresh anonymous browser window.

It is a good idea to start out with a R=302 temporary redirection and only change that to a R=301 permanent redirection once you are satisfied.

  • Related