繁体   English   中英

[apache] [。htaccess]可选的斜杠

[英][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.

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