我有以下代码......
RewriteEngine On
RewriteRule ^(css|js|admin|scripts|É)(/|$) - [L]
RewriteCond %{DOCUMENT_ROOT}$0 -d
RewriteRule ^[^/]+ - [L]
# Redirect .htm to index.php
RewriteRule ^(.*)\.htm /index.php?name=$1&id=$2 [L]
RewriteRule ^(.*)\ /index.php?name=$1&id=$2 [L]
哪种方法正常。
但是我需要添加301个重定向,所以我添加了以下内容:
# Below are the re-directs needed.
Redirect 301 /oldlink.htm /newlink.htm
当我输入oldlink.htm但是我得到newlink.htm?name = oldlink& id =
这不是我想要的,我需要它来转到newlink.htm
有人可以帮忙吗?
答案 0 :(得分:1)
RewriteCond
才能阻止在301之后应用规则。用以下代码替换您的代码:
RewriteEngine On
RewriteRule ^oldlink\.htm$ /newlink.htm [L,R=301,NC]
# Redirect .htm to index.php
RewriteRule ^(.*)\.html?$ /index.php?name=$1 [L,QSA,NC]
## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]
RewriteRule ^(css|js|admin|scripts|É)/?$ - [L]
## DON'T KNOW WHAT THIS RULE IS DOING
#RewriteRule ^(.*)\ /index.php?name=$1 [L,QSA,NC]