多个页面的 htaccess 不起作用

发布于 2025-01-12 21:01:54 字数 1588 浏览 3 评论 0原文

首先解释我想要做什么: 我的网站上有不同的页面。有些页面具有相同的模板,因此我创建一个带有参数的页面来适应我的页面:参数称为 pageview 和 lang,URL 如下所示:

http://mywebsite/home/en <- http://mywebsite/index.php?pageview=home&lang=en

http://mywebsite/page2/fr <- http://mywebsite/index.php?pageview=page2&lang=fr

例如。为此,我使用了著名的 .htaccess 文件及其 Apache 的 rewrite_module 模块。

我还有一个带有不同模板的联系页面。它的 URL 如下所示,这里只有一个参数:

http://mywebsite/contact/fr <- http://mywebsite/contact.php?lang=fr

http://mywebsite/contact/en <- http://mywebsite/contact.php?lang=en

这是我的 .htaccess 代码:

RewriteEngine On

RewriteRule ^contact/([a-zA-Z0-9]+)/?$ contact.php?lang=$1

RewriteRule ^([a-zA-Z0-9]+)$ index.php?pageview=$1 [QSA]
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ index.php?pageview=$1&lang=$2 [QSA]

问题是那.htaccess 文件适用于index.php,但不适用于contact.php

我可以完全访问contact.php,但未检测到参数

感谢您的帮助

Start by explaining what I'm trying to do:
I've got different pages on my website. Some pages have the same templates so I create one page with parameters to adapt my page: Parameters are called pageview and lang the URL looks like this:

http://mywebsite/home/en <- http://mywebsite/index.php?pageview=home&lang=en

http://mywebsite/page2/fr <- http://mywebsite/index.php?pageview=page2&lang=fr

for example. To dot that, I use the famous .htaccess file and it module rewrite_module for Apache.

I've got also a contact page with a different template. It URL looks like this and here there is only one parameter:

http://mywebsite/contact/fr <- http://mywebsite/contact.php?lang=fr

http://mywebsite/contact/en <- http://mywebsite/contact.php?lang=en

Here is my .htaccess code:

RewriteEngine On

RewriteRule ^contact/([a-zA-Z0-9]+)/?$ contact.php?lang=$1

RewriteRule ^([a-zA-Z0-9]+)$ index.php?pageview=$1 [QSA]
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ index.php?pageview=$1&lang=$2 [QSA]

The problem is that .htaccess file work for the index.php but not for contact.php

I can fully access to contact.php but the parameter is not detected

Thanks for your help ???????? !

EDIT

If I remove index parts to stay only the contact rewriteRule's the problem stay there.

contact.php and index.php are in the root folder

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

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

发布评论

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

评论(1

迷雾森÷林ヴ 2025-01-19 21:01:54
RewriteRule ^contact/([a-zA-Z0-9]+)/?$ contact.php?lang=$1

看起来您可能与 MultiViews 发生冲突。如果启用了 MultiViews,则 mod_negotiation 会将 /contact/fr 的请求重写为 /contact.php(不带任何参数) mod_rewrite 之前处理请求。

尝试在 .htaccess 文件顶部禁用 MultiViews:

Options -MultiViews
RewriteRule ^contact/([a-zA-Z0-9]+)/?$ contact.php?lang=$1

It looks like you may have a conflict with MultiViews. If MultiViews is enabled then mod_negotiation will rewrite a request for /contact/fr to /contact.php (without any parameters) before mod_rewrite is able to process the request.

Try disabling MultiViews at the top of your .htaccess file:

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