skip to Main Content

Have redirect issue. I want to make rewrite extension from php to html all of my url’s so i add this rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?).html$ $1.php [NC,L]

Works amaizing, i can view page when i go to example: /index.html
But its not good for SEO because when i can visit page also from index.php …
How to make good redirect? When i try redirect using this code:

RewriteCond %{REQUEST_URI} ^/index.php$ [NC] 
RewriteRule ^index.html  /index.php [R=301,L,NC]

It’s not working not redirect… Where I make a mistake?

2

Answers


  1. You need an additional rewriterule to internally redirect /index.html to /index.php try :

    ##1)redirect /index.php to /index.html##
    RewriteCond %{THE_REQUEST} /index.php [L,R,NC]
    RewriteRule ^ /index.html [NC,L,R]
    ##2)internally redirect /index.html to /index.php##
    RewriteRule ^index.html$ /index.php [L,NC]
    
    Login or Signup to reply.
  2. Don’t make a redirect but serve php as html like this:

    # Process PHP within .html  
    AddType application/x-httpd-php .php .htm .html
    

    (You have to rename your file.php into file.html)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search