简体   繁体   中英

How to hide php file extension from url from all files?

I have a lot of php files, but I stuck in this that I want to hide php extension from url in for all files without the need to edit my code. Another problem is that the website use $_GET to caught many parameters from links, headers, forms, is there a way to hide parameters from url or at least to change how it looks without effecting the website functionality.

I tried this but didnot work :

 Options -MultiViews
 RewriteEngine On

 RewriteCond %{THE_REQUEST} \ /+([^\?]+)\.php\?pid=([0-9]+)
 RewriteRule ^ /%1/%2? [L,R]

 RewriteCond %{THE_REQUEST} \ /+([^\?]+)\.php(\ |$)
 RewriteRule ^ /%1 [L,R]

 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{DOCUMENT_ROOT}/$1.php -f
 RewriteRule ^([^\.]+)/([0-9]+)$ /$1.php?pid=$2 [L]

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

Try this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

Try out below code in .htaccess file

# Turn on the rewrite engine
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM