mod_rewrite将旧请求URL转换为新请求

时间:2010-07-07 10:35:39

标签: mod-rewrite url-rewriting

.hello - 我需要转换旧网址请求以适应新网站内容;

即'艺术顾问'曾经是'咨询',所以如何抓住'咨询'网址并将其转化为'艺术咨询'

MY RULE if ^ consultancy $ MAKE ^ art-consultancy $并继续遵守以下规则......

RewriteRule ^art-consultancy$ consultancy-02.php [L]
RewriteRule ^art-consultancy/$ consultancy-02.php [L]

RewriteRule ^art-consultancy/([a-zA-Z0-9\-]+)$ consultancy-02.php?section=$1 [L]
RewriteRule ^art-consultancy/([a-zA-Z0-9\-]+)/$ consultancy-02.php?section=$1 [L]
#
RewriteRule ^art-consultancy/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)$ article-01.php [L]
RewriteRule ^art-consultancy/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/$ article-01.php [L]

任何帮助表示赞赏!

PS。尝试重定向/咨询/艺术咨询没有任何运气。认为这个方法需要一个实际的文件?

最好,Dc

1 个答案:

答案 0 :(得分:1)

你基本上只需完成你所说的你想做的事情,就像你用其他规则做的那样,所以我不确定这对于“回答”的方式有多少限定......但是,为了完整起见,我会继续写完整篇文章:

(另外,我将你的其他规则压缩成单行)

# Add in this condition because consultancy-02.php matches here too
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^consultancy(.*)$ art-consultancy$1

RewriteRule ^art-consultancy/?$ consultancy-02.php [L]
RewriteRule ^art-consultancy/([a-zA-Z0-9\-]+)/?$ consultancy-02.php?section=$1 [L]
RewriteRule ^art-consultancy/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ article-01.php [L]

如果您希望在用户的浏览器网址中将consultancy转换为art-consultancy,则应将第一个RewriteRule替换为:

RewriteRule ^consultancy(.*)$ /art-consultancy$1 [R=301,L]

我不完全确定为什么Redirect不能像你预期的那样工作。如果您查看服务器的error_log它可能会告诉您,但是如果不知道您网站的目录结构是什么,就很难推测。