需要一些关于 apache mod-rewrite 问题的帮助

发布于 2024-08-27 08:20:50 字数 741 浏览 3 评论 0原文

我已修改我的 .htaccess 文件以包含以下语句

RewriteCond $1 !^index.php$
RewriteRule ^/?([^/]+)$ index.php?c=home&m=details&seo=$1 [L,NS]

这允许我像这样使用产品 URL: http://domain .com/product_name

但是,当尝试访问与index.php同一级别的文件时,它总是调用上面的RewriteRule并出错。

我需要能够访问如下文件,但每个 URL 当前都尝试加载 index.php。 http://domain.com/about.htm
http://domain.com/terms.htm
http://domain.com/robots.txt

关于如何修改我的 htaccess 文件以使其正常工作有什么建议吗

I've modified my .htaccess file to have the following statement

RewriteCond $1 !^index.php$
RewriteRule ^/?([^/]+)$ index.php?c=home&m=details&seo=$1 [L,NS]

This allows me to use product URL's like this: http://domain.com/product_name

However, when trying to access a file at the same level as index.php, it always calls the RewriteRule above and errors out.

I need to be able to access files like below, but each URL currently attempts to load index.php.
http://domain.com/about.htm
http://domain.com/terms.htm
http://domain.com/robots.txt
etc

Any suggestions on how I can modify my htaccess file to get this to work correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

无法回应 2024-09-03 08:20:50

如果您希望文件胜过产品,您可以考虑另一个条件:

RewriteCond $1 !^index.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?([^/]+)$ index.php?c=home&m=details&seo=$1 [L,NS]

...这意味着只有当请求的 URI 未映射到文件时,才应将其视为产品。

拥有像这样的文件胜过产品并不可怕,除非您计划拥有名称为“something.html”和“dynamic.php”或“lenna.jpg”的产品。

If you want files to trump products you could toss in another condition:

RewriteCond $1 !^index.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?([^/]+)$ index.php?c=home&m=details&seo=$1 [L,NS]

...meaning that only if the requested URI doesn't map to a file should it be treated as a product.

Having files trump products like this isn't terrible unless you plan on having products with names like "something.html" and "dynamic.php" or "lenna.jpg".

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