多个页面的 htaccess 不起作用
首先解释我想要做什么: 我的网站上有不同的页面。有些页面具有相同的模板,因此我创建一个带有参数的页面来适应我的页面:参数称为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您可能与 MultiViews 发生冲突。如果启用了 MultiViews,则 mod_negotiation 会将
/contact/fr
的请求重写为/contact.php
(不带任何参数)在 mod_rewrite 之前处理请求。尝试在
.htaccess
文件顶部禁用 MultiViews: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: