简体   繁体   中英

Mod_rewrite to remove double directory

I have a URL that follows the below format.

https://example.com/dir/dir/article/

is it possible to rewrite this URL in htaccess to

https://example.com/dir/article/

I have a site where this double directory with the same name exists and i'm looking to strip this out but it still resolve to the correct place. Is this possible?

You can use this rule in your site root .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/([^/]+)(/\1/.*)$
RewriteRule ^ %2 [L,NE,R=301]

\\1 is back-reference of directory name matched by first capture group.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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