Simply remove a url segment with .htaccess

2020-02-12 05:58发布

I am simply trying to get this URL:

http://foo.com/entry/random-entry-123

to redirect to:

http://foo.com/random-entry-123

The "random-entry-123" is dynamic.
Different for each entry. Any help with this is greatly appreciated!

2条回答
手持菜刀,她持情操
2楼-- · 2020-02-12 06:28

Although this has already been answered, it didn't work for me when I had two segments after the first, eg:

http://foo.com/entry/random-segment/random-entry-123

Instead this worked for me and also takes care of 301 redirects:

RedirectMatch 301 /entry/(.*) /$1

Hope this helps.

查看更多
Ridiculous、
3楼-- · 2020-02-12 06:49

Assuming no further rewrites are in use, and all links inside /entry/ are to rewritten, then try this:

RewriteEngine on
RewriteBase /

RewriteRule ^/entry/(.+)$ /$1 [L,QSA]

Lose the [L] if there are further rewrites ahead in the file.

查看更多
登录 后发表回答