简体   繁体   中英

Do I still need to remove extensions in every href for htaccess to work?

Hello I am currently using wampserver and this code to remove file extensions.

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

Yes, it is working but, I have lots of php files. Is there a way that it can automatically remove file extensions without me removing it from hrefs like <a href="index.php"> to <a href="index"> ? And also I have links like http://www.whatever.ph/index.php?pid=51 and I want it to be like http://www.whatever.ph/index/51 or what is a better link for that

You can do some global search/replace to get rid of all the .php extensions. You really want to change the links in your html otherwise you'll need to create mod_rewrite rules to redirect the browser for every request that has an extension or the ugly looking links.

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]

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