重定向已使用参数重写URL

时间:2016-11-17 15:33:34

标签: .htaccess redirect mod-rewrite url-rewriting

为了编辑我的实际网址结构。我需要重定向“旧”链接以保持传入链接处于活动状态。

一切正常,但是当“旧”链接有参数时,它不起作用。

这是我的.htaccess的第一部分(正在运作):

Options +FollowSymlinks -MultiViews
RewriteEngine On

# Rewrite the "old" url "/models" to "/models-pictures"
RewriteRule ^/?models/?$ /models-pictures [R=301,NE,L]

# New redirection
RewriteCond %{REQUEST_URI} /models-pictures/?$ [NC]
RewriteRule . models.php [L]

现在第二部分没有重定向

# Rewrite the "old" url "/models/[name]-pictures" to "/[name]-pictures" 
RewriteRule ^/?models/([a-z\-A-Z]+)-pictures/?$ /%1-pictures [R=301,NE,L] <- Not working

# New redirection
RewriteCond %{REQUEST_URI} /([a-z\-A-Z]+)-pictures/?$ [NC]
RewriteRule . orderby.php?model=%1 [L,QSA]

# New redirection
RewriteCond %{REQUEST_URI} /([a-z\-A-Z]+)-pictures/([a-z\-A-Z]+)/?$ [NC]
RewriteRule . p.php?model=%1&media=%2 [L,QSA]

有什么想法吗?谢谢。

1 个答案:

答案 0 :(得分:1)

您未在非工作规则中的替换字符串中使用正确的反向引用。您有%1,它应该是$1

# Rewrite the "old" url "/models/[name]-pictures" to "/[name]-pictures" 
RewriteRule ^/?models/([a-z\-A-Z]+)-pictures/?$ /$1-pictures [R=301,NE,L]
相关问题