.htaccess RewriteRule 将目录类型 URL 结构转换为查询
我知道这个问题已经被问/回答过好几次了,但我似乎无法克服它。所以,我很抱歉...
在网站开发阶段,我希望浏览器地址栏显示:domain.com/dev/item
我希望 RewriteRule 将其更改为:domain.com/dev/index.php?p=item
我使用位于 public_html 目录中的 .htaccess 来实现此目的。 public_html/dev 中的 .htaccess 工作正常,配置为将所有不使用我的 IP 的人重定向到 domain.com。我的 apache 版本是 2.2.15,我已经确认我能够使用 .htaccess 进行重定向,但顶级 .htacess 根本不起作用。这是我使用的代码:(
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^dev/(.*)$ dev/index.php?p=$1 [NC]
#variations tried: ^dev/(.*)+$, ^dev/(.*)+?$
包括变体)导致 404,/dev/item 未找到。从 ^dev/(.*)$ 中删除 dev/ 会产生正确的 url 格式,但会出现以下服务器变量:
[REDIRECT_QUERY_STRING] => p=
[REDIRECT_URL] => /404.shtml
[QUERY_STRING] => p=
[REQUEST_URI] => /dev/item
我的目标是进行一些小更改以支持实时站点和开发副本的这种类型的重写。但我就是不明白我做错了什么。我真的很感激任何帮助。
i know this question has been asked/answered several times already, but i just cant seem to get past it. so, my apologies...
while in the site dev phase, i want the browsers address bar to display: domain.com/dev/item
i would like the RewriteRule to change it to: domain.com/dev/index.php?p=item
im using the .htaccess located in the public_html directory for this. the .htaccess within public_html/dev, which works fine, is configured to redirect everybody who is not using my ip to domain.com. my apache version is 2.2.15 and i've confirmed that i am able to redirect using .htaccess, but the top level .htacess simply doesnt work. here is the code im using:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^dev/(.*)$ dev/index.php?p=$1 [NC]
#variations tried: ^dev/(.*)+$, ^dev/(.*)+?$
the, including variations, results in a 404, /dev/item not found. removing the dev/ from ^dev/(.*)$ results in the correct url format, but the following server variables:
[REDIRECT_QUERY_STRING] => p=
[REDIRECT_URL] => /404.shtml
[QUERY_STRING] => p=
[REQUEST_URI] => /dev/item
my goal is to make a small change to support this type of rewrite for both the live site and the dev copy. but i just cant understand what im doing wrong. i really would appreciate any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在重写路径的开头指定 / 。
试试这个:
You need to specify the / at the beginning of the rewrite paths.
Try this instead: