使用 .htaccess 获取 index.php
我在 .htaccess 中使用了一堆 ReWrite 规则,例如这些
RewriteRule ^brochure/([^/]+)/?$小册子.php?cat_path=$1
这一切都工作得很好,感谢我通过搜索该网站找到的答案。但我有一个小小的障碍。
这条规则目前完美运行 RewriteRule ^([a-zA-Z0-9_-]+)?$ $1.php
它捕获我所有的网址,例如 www.mysite.com/shane
并请求 < code>shane.php - 到目前为止一切顺利,但是当我调用 www.mysite.com
时,我需要它来请求 index.php
我可以使用哪个规则用于这个?
谢谢人们。
更新 - 为了未来需要类似帮助的用户。
我的 ^([a-zA-Z0-9_-]+)?$ $1.php
规则导致了我上面提到的问题。此类规则不需要问号 ?
,当您删除问号时,目录中的 index.php 文件将恢复为默认登录页面。感谢托马拉克的帮助。
I'm using a bunch of ReWrite rules in my .htaccess such as these
RewriteRule ^brochure/([^/]+)/?$ brochure.php?cat_path=$1
It's all working great thanks to answers I found by searching this site. But I've got a tiny little snag.
This rule works perfecty at the momentRewriteRule ^([a-zA-Z0-9_-]+)?$ $1.php
It catches all my urls like www.mysite.com/shane
and requestes shane.php
- So far so good, but when I call www.mysite.com
I need it to request index.php
Which rule could I use for this?
Thanks people.
UPDATE - For the sake of future users needing similar help.
My rule of ^([a-zA-Z0-9_-]+)?$ $1.php
was causing the problem I mentioned above. The question mark ?
is not needed in this type of rule, when you remove the question mark the index.php file in the directory returns to being the default landing page. Thanks to Tomalak for the Help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你不需要任何规则。只需确保
.php
目录的默认索引文件,它就会自动发生。更新
我认为您的规则
实际上应该这样
,以便它不会与未给出文件名的请求(您想要定向到
index.php
)发生冲突。You don't need any rule for it. Just make sure that
.php
default index files for the directory and it'll happen automatically.Update
I think that your rule
should in fact be
so that it does not conflict with requests where the filename isn't given (which you want to direct to
index.php
).我认为这就是您正在寻找的,不确定的想法:
I think this is what you're looking for,not sure thought:
您可以按照 Tomalak 的说明进行操作,并确保 DirectoryIndex 设置为加载
index.php
。或者接近詹姆斯所说的,
You can either do as Tomalak says, and ensure the DirectoryIndex is set to load
index.php
.Or close to what James says,