使用 .htaccess 获取 index.php

发布于 2024-11-03 06:09:53 字数 588 浏览 1 评论 0原文

我在 .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 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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦冥 2024-11-10 06:09:53

你不需要任何规则。只需确保 .php 目录的默认索引文件,它就会自动发生。

更新

我认为您的规则

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

实际上应该这样

^([a-zA-Z0-9_-]+)$ $1.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

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

should in fact be

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

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

辞慾 2024-11-10 06:09:53

我认为这就是您正在寻找的,不确定的想法:

RewriteRule ^/$ index.php

I think this is what you're looking for,not sure thought:

RewriteRule ^/$ index.php
冰葑 2024-11-10 06:09:53

您可以按照 Tomalak 的说明进行操作,并确保 DirectoryIndex 设置为加载index.php

或者接近詹姆斯所说的,

RewriteRule ^/?$ index.php [L]

You can either do as Tomalak says, and ensure the DirectoryIndex is set to load index.php.

Or close to what James says,

RewriteRule ^/?$ index.php [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文