2

I would like to permanently redirect these urls only:

http://www.example.com/privacy.php
http://www.example.com/terms.php
http://www.example.com/contacts.php

to:

http://www.example.com/privacy
http://www.example.com/terms
http://www.example.com/contacts

Continuing to serve the contents inside corresponding .php files.

Any help would be greatly appreciated!

Thank you.

P.S. I edited my question because it has been identified as a possible duplicate of another question; the answer of the suggested question doesn't solve my problem

This is .htaccess current content:

RewriteEngine On   
RewriteBase /   

# Adds the www. before any URL   
RewriteCond %{HTTPS} !=on   
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]   
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]   

# Redirects index.php page to the homepage   
RewriteRule ^index\.php/?$ / [R=301,L]   

# Redirects all old pages example.com/?d=124575 to http://www.example.com   
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /\?(.*)\ HTTP   
RewriteRule ^ /? [R=301,L]   
Benedictus
  • 21
  • 2

2 Answers2

0

This will do it for you:

RewriteRule ^(privacy|terms|contacts)$ $1.php
  • Thank you for your answer, but it doesn't work, 404 error – Benedictus May 10 '17 at 04:57
  • Where are you putting the rules and what are you visiting? –  May 10 '17 at 05:56
  • I put the rules at the end of my .htaccess, this is the content:
    RewriteEngine On RewriteBase / # Adds the www. before any URL RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^www\..+$ [NC] RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] # Redirects index.php page to the homepage RewriteRule ^index\.php/?$ / [R=301,L] # Redirects all old pages example.com/?d=124575 to http://www.example.com RewriteCond %{THE_REQUEST} ^(GET|POST)\ /\?(.*)\ HTTP RewriteRule ^ /? [R=301,L]
    – Benedictus May 10 '17 at 08:23
  • And what happens when you add the rule I provided to the end of that, and then visit `/privacy`? –  May 10 '17 at 16:27
0

This is what I use on my website.

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [L]

And it works without a failure.

RealSollyM
  • 1,530
  • 1
  • 22
  • 35