简体   繁体   English

在apache2服务器中通过htaccess删除URL的某些部分

[英]Remove some parts of url by htaccess in apache2 server

I'm trying to rewrite url by .htaccess on apache2 server in ubuntu 14.04. 我正在尝试在Ubuntu 14.04的apache2服务器上通过.htaccess重写url。 I have the following url : 我有以下网址:

localhost/compare/compares/single/16/postoneVSposttwo

But I want it like: 但我想要这样:

 localhost/compare/compares/postoneVSposttwo

I have tried by following .htaccess rules: 我已经尝试通过遵循.htaccess规则:

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

But it make a url like: 但是它会生成一个URL,例如:

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

How can I solved the problem? 我该如何解决这个问题?

You can use this rule: 您可以使用以下规则:

RewriteEngine on

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM