在apache2服务器

时间:2015-10-21 14:28:46

标签: regex apache .htaccess url model-view-controller

我试图在ubuntu 14.04中的apache2服务器上重写.htaccess的url。我有以下网址:

localhost/compare/compares/single/16/postoneVSposttwo

但我希望它像:

 localhost/compare/compares/postoneVSposttwo

我试过遵循.htaccess规则:

RewriteEngine on
RewriteRule ^(.+)/single/.+/(.+)$ $1/$2 [L,NC,R]

但它有一个网址:

localhost/var/www/html/compare/webroot/compares/postoneVSposttwo

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您可以使用此规则:

RewriteEngine on

RewriteRule ^(.+?)/single/[^/]+/(.+)$ /compare/$1/$2 [L,NC,R=302]