任何人都可以幫助我刪除URL中的.html或.php擴展名。刪除.html或.PHP URL擴展名使用.htaccess不起作用
我在下面的代碼在我的php項目中嘗試,但它不工作。 我已經嘗試了這麼多的.htaccess代碼,但沒有幫助我..提前
任何人都可以幫助我刪除URL中的.html或.php擴展名。刪除.html或.PHP URL擴展名使用.htaccess不起作用
我在下面的代碼在我的php項目中嘗試,但它不工作。 我已經嘗試了這麼多的.htaccess代碼,但沒有幫助我..提前
以前我也遇到問題
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.php
由於與刪除的.html或.php擴展形式的URL。
我有一個解決方案在這裏
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase/
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule^%1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule^%{REQUEST_URI}.php [L]
把上面的代碼中的.htaccess文件,上面的代碼是.php文件。 爲.html文件要經過下面的代碼
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase/
## hide .php extension
# To externally redirect /dir/foo.html to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule^%1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule^%{REQUEST_URI}.html [L]
我剛剛更換.php爲以.html
希望它可以幫助你.. :)
是'.htaccess'文件確實有效?例如,你使用Apache httpd嗎?你是否啓用了'rewrite'模塊? – FelisCatus
我正在運行XAMPP,並且我已經在我的htdocs文件夾中創建了.htaccess現在爲我所有在htdocs中的項目工作,任何方式都是謝謝FelisCatus – Raily