简体   繁体   中英

How to redirect all extensions after .php to the file with .php using .htaccess

According to Google Webmaster Tools, I have many crawl errors related to weird URL extensions added to my existing pages.

For example, this page is displayed normally: http://www.normalbreathing.com/causes/cold-feet-hands-causes.php

However, somehow, there are these weird URLs somehow generated from the previous URL: http://www.normalbreathing.com/causes/cold-feet-hands-causes.php/CO2.php and similar others.

These weird URLs are displayed in major browsers, but with many mistakes (no images and all links wrong). As a result, these weird pages generate numerous crawl errors for bots.

How can I redirect all extensions after ".php" (note that these weird extensions often have extra ".php" or something like "/%20" etc.) to the correct files with only one ".php" using .htaccess?

I found a similar query: .htaccess redirect all extension to php

but it is not exactly the same because it says "To use it, be sure that you don't have URL with a dot and an alphanumeric string at the end." I do have those dots and sometimes strings with numbers after ".php".

Google is referring to the .php/.php on your URL. a site that I have found useful is:

http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html

There are really major problems with your website.

Just point all your css, js, images to absolute paths like so:

<link rel="stylesheet" href="http://www.normalbreathing.com/text2.css" type="text/css" />

Whenever you have a / it figures that it's a directory. So going ../ will not point to the proper place.

Same story with hrefs. not one link from here http://www.normalbreathing.com/d/cold-feet.php/CO2.php works. Because it starts with ../

I strongly recommend fixing HTML before going into .htaccess

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