.htaccess重写规则不起作用,<;名称>;。加载php而不是index.php?page=<;名称>;
我们有一个具有以下文件结构的网站:.htaccess重写规则不起作用,<;名称>;。加载php而不是index.php?page=<;名称>;,php,apache,.htaccess,redirect,mod-rewrite,Php,Apache,.htaccess,Redirect,Mod Rewrite,我们有一个具有以下文件结构的网站: /www /nl index.php contact.php ... /fr index.php contact.php ... /de index.php contact.php ... index.php .htaccess www文件夹中的index.php文件是一个语言
/www
/nl
index.php
contact.php
...
/fr
index.php
contact.php
...
/de
index.php
contact.php
...
index.php
.htaccess
www
文件夹中的index.php
文件是一个语言选择页面,链接到nl
、fr
和de
文件夹中的index.php
文件。后一个index.php页面构建网页并从.php
加载页面内容
过去,页面的加载方式如下:
http://www.ourdomain.com/nl/index.php?page=contact
RewriteEngine On
# RewriteBase wijzigen in / (online)
RewriteBase /
# PDF: redirect pdf file in wrong directory to root language directory (nl/fr/en)
RewriteRule ^(nl|fr|de)(/[a-zA-Z0-9\-/]+)+/([a-zA-Z0-9\-]+.pdf)/?$ $1/$3 [NC,L,R=301]
# pages: redirect index.php in wrong directory to the correct language directory (nl/fr/en)
RewriteRule ^(nl|fr|de)(/[a-zA-Z0-9\-/]+)+/(index.php)/?$ $1/$3 [NC,L]
# pages: convert SEO friendly url to index.php?page=<page>
RewriteRule ^(nl|fr|de)(/[a-zA-Z0-9\-/]+)*/([a-zA-Z0-9\-]+)/?$ $1/index.php?page=$3 [NC,L]
这将把/nl/contact.php
的内容加载到站点结构中
为了使网站SEO更友好,我们将此更改为:
http://www.ourdomain.com/nl/contact
这可以达到3级深度(/nl/nav-level1/nav-level2/nav-level3
)
nl
、fr
和de
文件夹中的index.php文件有一个算法,可以将旧页面url重定向到新页面url,供从旧url访问站点的用户使用
header( 'HTTP/1.1 301 Moved Permanently' );
header('location:' . $newurl);
exit;
根www目录中的.htaccess文件如下所示:
http://www.ourdomain.com/nl/index.php?page=contact
RewriteEngine On
# RewriteBase wijzigen in / (online)
RewriteBase /
# PDF: redirect pdf file in wrong directory to root language directory (nl/fr/en)
RewriteRule ^(nl|fr|de)(/[a-zA-Z0-9\-/]+)+/([a-zA-Z0-9\-]+.pdf)/?$ $1/$3 [NC,L,R=301]
# pages: redirect index.php in wrong directory to the correct language directory (nl/fr/en)
RewriteRule ^(nl|fr|de)(/[a-zA-Z0-9\-/]+)+/(index.php)/?$ $1/$3 [NC,L]
# pages: convert SEO friendly url to index.php?page=<page>
RewriteRule ^(nl|fr|de)(/[a-zA-Z0-9\-/]+)*/([a-zA-Z0-9\-]+)/?$ $1/index.php?page=$3 [NC,L]
而不是http://www.ourdomain.com/nl/contact
我总是被重定向到http://www.ourdomain.com/nl/contact/?page=contact
如果我转到http://www.ourdomain.com/nl/contact/
get变量不会添加到url中
我已经在这个问题上工作了好几个小时,找了好几个小时,但我还是没有意识到这一点。任何有价值的意见都将不胜感激。我刚刚找到了问题的答案
显然,
MultiViews
是在新服务器上设置的。因此,没有扩展名的文件名与具有扩展名的文件匹配,导致http://example.com/nl/contact
加载http://example.com/nl/contact.php
您是否设置了允许覆盖文件信息选项
?