【问题标题】:htaccess Rewrite rule for accessing without php extension causes error on trailing slashhtaccess 重写规则以在没有 php 扩展的情况下访问导致斜杠错误
【发布时间】:2018-01-17 05:10:52
【问题描述】:

这是我目前访问不带扩展名的 php 文件的重写规则。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

但是,我希望能够像这样格式化 URL,

https://example.com/somefile/parameter

所以,像,

https://example.com/check_user/12345

但是,当斜杠 (/) 后面有尾随参数时,我得到 500 Internal Server Error。

我真的很想深入了解这个重写规则并征服它,但我根本没有时间这样做。 (按生产要求。)

非常感谢您的帮助。

【问题讨论】:

标签: php apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

我似乎已经用这个修复了它。

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

在这里得到它。 Remove .php extension with .htaccess

【讨论】:

    猜你喜欢
    • 2014-10-22
    • 2013-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-29
    • 1970-01-01
    相关资源
    最近更新 更多