使用.htaccess获取index.php [英] get the index.php with .htaccess

查看:48
本文介绍了使用.htaccess获取index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.htaccess中使用了诸如此类的一堆ReWrite规则

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.

此规则目前完美无缺 RewriteRule ^([a-zA-Z0-9_-]+)?$ $1.php它会捕获我的所有URL,例如www.mysite.com/shane并请求shane.php-到目前为止还不错,但是当我调用www.mysite.com时,我需要它来请求index.php

This rule works perfecty at the moment RewriteRule ^([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

我可以使用哪个规则?

谢谢.

更新-为了将来的用户需要类似的帮助.

UPDATE - For the sake of future users needing similar help.

我的^([a-zA-Z0-9_-]+)?$ $1.php规则导致了我上面提到的问题.在这种类型的规则中,不需要问号?,当您删除问号时,目录中的index.php文件将返回为默认登录页面.感谢Tomalak的帮助.

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.

推荐答案

您不需要任何规则.只需确保该目录的.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.

更新

我认为您的规则

^([a-zA-Z0-9_-]+)?$ $1.php

实际上应该是

^([a-zA-Z0-9_-]+)$ $1.php

,以使其与未提供文件名的请求不冲突(您希望将其定向到index.php).

so that it does not conflict with requests where the filename isn't given (which you want to direct to index.php).

这篇关于使用.htaccess获取index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆