I have a problem whereby google has indexed some pages with the wrong URL.
The URL they are indexing is:
http://www.example.com/user/emp.php
and HTML URL:
http://www.example.com/login.html
I need it to redirect to:
http://www.example.com/user/emp
and HTML URL:
http://www.example.com/login
here is my .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Make sure you have the mod_rewrite module is installed, Check the output of phpinfo();
function to confirm. I think the following .htaccess
is fine. Place the htaccess in the root of your application.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Read This on how to install mod_rewrite in php
Replace it with this code in your htacess file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
And please remove .html and .php from all your links which you are calling for example.
<a href="index.html">Home</a>
To
<a href="index">Home</a>
First check, if there exists an appropriate target ending in .html
or .php
, then rewrite to that URL
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)$ $1.html [L]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)$ $1.php [L]
# Remove .html-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)$ $1.html