[英]RewriteRule same name as directory
For my site I have a directory called /test/
.对于我的网站,我有一个名为/test/
的目录。 I want to rewrite www.example.com/nl/test
and www.example.com/nl/test/
to a certain page ( test.php
).我想将www.example.com/nl/test
和www.example.com/nl/test/
重写到某个页面( test.php
)。
RewriteRule ^(nl|en)$ http://www.example.com/$1/ [NC,R]
RewriteBase /
RewriteRule ^(nl|en)$ $1/ [NC,R]
RewriteCond $1 !^(en|nl)$
RewriteRule ^([a-z]{2})/(.*)$ en/$2 [L,R=302]
RewriteRule ^(nl|en)/(.*)$ $2?language=$1&%{QUERY_STRING} [L]
RewriteRule ^sale$ sale.php
RewriteRule ^valentine$ valentine.php
RewriteRule ^test/$ test.php
The redirect of www.example.com/nl/test/
is correct. www.example.com/nl/test/
的重定向是正确的。 The language parameter is also correctly rewritten.语言参数也被正确重写。
For the second redirect (the version without the trailing slash) I can't get this working.对于第二个重定向(没有斜杠的版本),我无法正常工作。
RewriteRule ^test$ test.php
Now my URL is rewritten as www.example.com/test/?language=nl
现在我的 URL 被重写为www.example.com/test/?language=nl
Can someone give me a tip or hint to fix this?有人可以给我一个提示或提示来解决这个问题吗? I can't change the name of the directory since there are several external URLs linking to this directory.我无法更改目录的名称,因为有几个外部 URL 链接到该目录。
This rule will do the whole job (instead of 4 lines you have there): it will rewrite both /nl/test
and /nl/test/
to /test.php?language=nl
.这条规则将完成整个工作(而不是你在那里的 4 行):它将/nl/test
和/nl/test/
重写为/test.php?language=nl
。
RewriteRule ^(en|nl)/test/?$ /test.php?language=$1 [NC,QSA,L]
The [QSA]
flag will preserve any existing query string (therefore, there is no need for &%{QUERY_STRING}
). [QSA]
标志将保留任何现有的查询字符串(因此,不需要&%{QUERY_STRING}
)。
Options +FollowSymLinks -MultiViews
DirectorySlash Off
RewriteEngine On
RewriteBase /
RewriteRule ^(nl|en)$ http://www.example.com/$1/ [NC,R=301,L]
RewriteCond $1 !^(en|nl)$
RewriteRule ^([a-z]{2})/(.*)$ /en/$2 [R=302,L]
RewriteRule ^(nl|en)/(.*)$ /$2?language=$1 [NC,QSA,L]
RewriteRule ^sale/?$ sale.php [QSA,L]
RewriteRule ^valentine/?$ valentine.php [QSA,L]
RewriteRule ^test/?$ test.php [QSA,L]
There is no need for RewriteRule ^(nl|en)$ $1/ [NC,R]
as you already have RewriteRule ^(nl|en)$ http://www.example.com/$1/ [NC,R=301,L]
.不需要RewriteRule ^(nl|en)$ $1/ [NC,R]
因为你已经有了RewriteRule ^(nl|en)$ http://www.example.com/$1/ [NC,R=301,L]
。 It does the same job.它做同样的工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.