2013-06-25 82 views
0

我需要做的http://www.example.com/2-for-1重定向到http://www.example/article/1。 要么一切到目前为止,我已经试过不正确或服务器被搞砸了。重定向以破折号/连字符

有人能懂行请你告诉我正确的语法,所以我可以验证服务器是否设置不正确?

这些都是我的一些较新的尝试:

RewriteRule ^(.*)2(\-)for(\-)1$ http://www.example.com/article/1 [NC,R=301,L] 
RewriteRule ^(.*)/2\-for\-1$ /article/1 [NC,R=301,L] 
RewriteRule ^2-for-1/?$ article/1 [NC,L] 
+0

你的最后一个例子工程我。检查你没有一个规则,它会阻止它发生,并且你的.htaccess中有'RewriteEngine on'。 – icabod

+0

另外,你想在浏览器中看到重写的URL吗?如果是这样,你需要添加'[R]'标志。 – icabod

回答

0

启用mod_rewrite的,并通过httpd.conf的.htaccess,然后把这个代码在你.htaccessDOCUMENT_ROOT目录:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

RewriteRule ^[^-]+-for-([^/]+)/?$ /article/$1 [R=301,NC,L] 
相关问题