[英][apache][.htaccess] optional trailing slash
我希望.htaccess文件能夠處理可選的尾部斜杠,以便兩者
localhost/Stuff/Test
localhost/Stuff/Test/
將工作。 我一直在尋找答案,但是我發現我只需要'/?',我已經把它放了。 救命? 這是我的.htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{REQUEST_URI} !\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9]+)/?$ $1.php [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* custom_404.html [L]
</IfModule>
當前,它僅在不使用斜杠的情況下有效。
嘗試使用以下代碼隱藏php擴展名:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ custom_404.html [L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.