RewriteRule 可选尾部斜杠问题
正在开发一个应用程序,该应用程序与打开永久链接的 WordPress 网站并行构建。因此,稍后在 htaccess 中还有其他重写来处理 WordPress 的所有方面。但是,我正在尝试在实现这些之前执行一些我自己的重写。 - 当然在我的后面使用[L]。 一切都很完美,直到我尝试将选项添加到末尾,允许斜线或不斜线(并且仍然匹配)。
以下是在此服务器上引发 500 错误的示例:
RewriteRule ^app/([^/]+)/?$ /app/$1\.php [L,QSA]
http://<domain>.com/app/login
or
http://<domain>.com/app/login/
但以下内容工作得很好,并且位于 htaccess 中的前一个示例之上。
RewriteRule ^app/p/([^/]+)/?$ /app/page.php?page_slug=$1 [L,QSA]
http://<domain>.com/app/p/styles
or
http://<domain>.com/app/p/styles/
我尝试过一些变化,但几乎没有成功。
RewriteRule ^app/([^/]+)/{0,1}$ /app/$1\.php [L,QSA]
and
RewriteRule ^app/([^/]+)[p]/[\p]?$ /app/$1\.php [L,QSA]
Working on an application that I’m building in parallel to a wordpress site with permalinks turned on. So, there are other rewrites later in the htaccess that handle the catch-all aspects for wordpress. But, I’m attempting to perform some of my own rewrites before it gets to those. - and of couse using [L] after mine.
Everything is working perfect until I try to add the option to the end allowing a slash or no slash (and still make a match).
Here’s an example of what throws a 500 error on this server:
RewriteRule ^app/([^/]+)/?$ /app/$1\.php [L,QSA]
http://<domain>.com/app/login
or
http://<domain>.com/app/login/
But the following works just fine, and is above the previous example in the htaccess.
RewriteRule ^app/p/([^/]+)/?$ /app/page.php?page_slug=$1 [L,QSA]
http://<domain>.com/app/p/styles
or
http://<domain>.com/app/p/styles/
I've tried variations with little/no success.
RewriteRule ^app/([^/]+)/{0,1}$ /app/$1\.php [L,QSA]
and
RewriteRule ^app/([^/]+)[p]/[\p]?$ /app/$1\.php [L,QSA]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为您的目标位置
/app/$1.php
与源位置^app/([^/]+)/?$
完全匹配。因此页面被重定向到自身。This is because your target location
/app/$1.php
is perfectly matched for your source location^app/([^/]+)/?$
. So the page getting redirected to itself.