[英]How to remove .php extension from URL on server and on localhost with .htaccess file?
就像標題說的那樣,我需要從帶有 .htaccess RewriteRule
的 URL 中刪除 .php 。
https://example.com/about.php
應該
https://example.com/about
和
localhost:8080/about.php
應該
localhost:8080/about
這是我當前的.htaccess
文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>
您可以在站點根目錄 .htaccess 中使用這些規則:
RewriteEngine On
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]
## To internally rewrite /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
您可以將其添加到您的.htaccess
文件中,我將從 url 中刪除.php
擴展名
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.