2

I am stuck with .htaccess modification, need a little help.
First off, here is whats inside my htaccess.

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]

For example, I created the file named test.php and uploaded to my server.

I want my server to behave like this.

http://example.com/test/test.html -> http://example.com/test/test.html(as it is)
http://example.com/test/test.php -> http://example.com/test/test.html

but with the .htaccess I have right now, I still have both .php and .html which may be considered as file duplication by search engine crawler like Google robot (isn't it?).

Any help appreciated.

0

3 Answers 3

1

try this .htaccess code

# Enable Rewrite Engine
RewriteEngine on

#Create friendly URL
RewriteRule ^test/(.*)\.html$ test/$1\.php [L]

OR

RewriteCond %{REQUEST_URI} ^(.*)\.php$
RewriteRule ^(.*) /$1.html [L]

OR

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## .php to .html
# To externally redirect /test/test.php to /test/test.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1.html [R,L,NC]
Sign up to request clarification or add additional context in comments.

4 Comments

thanks Sumit for quick reply. But my file name can be anything. like index.php, company.php, mission.php, access.php, etc... so better to use regex right?
if that not work check my OR portion of answer, that will defiantly work
@norixxx you have test folder so rule may be RewriteCond %{REQUEST_URI} ^test/(.*)\.php$ RewriteRule ^test/(.*) /test/$1.html [L]
still not workin' /test/index.php -> O.K. but if i type /test/index.html -> "The requested URL /test/index.html was not found on this server." my server says. my htaccess now: RewriteEngine on RewriteCond %{REQUEST_URI} ^test/(.*)\.php$ RewriteRule ^test/(.*) /test/$1.html [L]
1

This is a configuration file of apache '.htaccess' if you still want to configure then change

RewriteEngine on

I hope this work

1 Comment

Thanks. I wrote 'RewriteEngine on' at first row in my htaccess. still doesn't work though.
1

You may try this in one .htaccess file in root directory:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !\.html             [NC]
RewriteRule ^([^/]+)/([^.]+)\.php  /$1/$2.html [R=301,NC,L]

For silent mapping, replace [R=301,NC,L] with [NC,L]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.