简体   繁体   中英

Remove directory name from URL using htaccess but keep parent page

Remove directory name from URL using htaccess, but keep the parent page.

https://www.example.com/faqs/page1/
https://www.example.com/faqs/page2/
https://www.example.com/faqs/page3/
https://www.example.com/faqs/page4/
https://www.example.com/faqs/page5/
https://www.example.com/faqs/page6/

to

https://www.example.com/page1/
https://www.example.com/page2/
https://www.example.com/page3/
https://www.example.com/page4/
https://www.example.com/page5/
https://www.example.com/page6/

But

https://www.example.com/faqs/ 

remains the same.

I tried

RedirectMatch 301 ^/faqs/(.*)$  https://www.example.com/$1

But it will make

https://www.example.com/faqs/ 

redirect to homepage too.

RedirectMatch 301 ^/faqs/(.*)$ https://www.example.com/$1

To exclude the /faq/ URL you just need to change the * (0 or more) quantifier to + (1 or more) in your capturing subpattern, so only /faqs/<something> matches and not /faqs/<anything> . For example:

RedirectMatch 301 ^/faqs/(.+)$  https://www.example.com/$1

You will need to clear your browser cache before testing.

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