简体   繁体   中英

htaccess redirect url to parent directory

I am getting an issue on my website. Google indexes many this kind of URLs:

http://example.com/folder/url1.php/url2.php

So, how can I redirect to my original URL, which in this case is:

http://example.com/folder/url1.php

There is another folder2 also in folder and only redirect if there is another url appended after url1.php

Frankly speaking, I am really new to this htaccess redirect, I never used this before.
So, any help will be really appreciated.

You can use RedirectMatch directive to redirect your URLs.

At the top of your htaccess file, add the following line:

RedirectMatch 301 ^/folder/([^/]+)/([^/]+)\.php$ https://example.com/folder/$1

To redirect a particular/single URI, you can use

RedirectMatch 301 ^/folder/file.php/file.php$ https://example.com/folder/file.php

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