1

我有以下代码...

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

任何人都可以帮忙吗?

4

1 回答 1

1
  1. 避免混合 mod_proxy 和 mod_rewrite
  2. 在 301 之后,您将需要RewriteCond阻止应用规则。
  3. 你的规则也不对。

用这个替换你的代码:

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]
于 2013-09-23T13:01:53.160 回答