PDA

View Full Version : 301 on a Apache Server.


john1111
01-29-2010, 09:29 AM
Hello to everyone,

I am all new to this sorry in advance if I do not make sence.................

I had my sites mark up which was built in tables built in php and the php was redircted to the .html extensions of the live site thats been live for a while i did not want to change the urls.

I need to 301 redirect the .php to the .html I added the some code to the .htaccess file and it has 301 redirected the


1, non www. to the www.

2, index.html and index.php to /

And the php extensions to html are still working but no matter what i do i cant seem to 301 the .php to the .html

Site name being www domain co uk





Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain\.co.uk [NC]
RewriteRule (.*) http://www.domain.co.uk/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.domain.co.uk/$1 [R=301,L]

# rewrite php extensions to html

RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^([^/]*).html$ $1.php



I would be very very greatful for any help recivied, spend two days reading here and there and no luck yet.

Thank you.

abduraooft
01-29-2010, 09:55 AM
RewriteCond %{HTTP_HOST} ^domain\.co.uk [NC]
RewriteRule (.*) http://www.domain.co.uk/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.domain.co.uk/$1 [R=301,L]
Don't you just need the following? RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
(See http://no-www.org/)

john1111
01-29-2010, 10:17 AM
Hi abduraooft,

No expert here I added this myself, this code 301 redirects

http://domain.co.uk to the correct url = http://www.domain.co.uk

RewriteCond %{HTTP_HOST} ^domain\.co.uk [NC]
RewriteRule (.*) http://www.domain.co.uk/$1 [R=301,L]

This 301 redirects

The http://www.domain.co.uk/index.html

to the correct url = http://www.domain.co.uk



RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.domain.co.uk/$1 [R=301,L]

The person who recoded the site added

# rewrite php extensions to html

RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^([^/]*).html$ $1.php



Which seem to redirect the php to the live .html urls I dont want to change the urls for the site as they have been live for a while you see.

But now the site can be seen at for example =

http://www.domain.co.uk/contact.php and http://www.domain.co.uk/contact.html

so I need to 301 redirect http://www.domain.co.uk/contact.php to the correct url http://www.domain.co.uk/contact.html

So only one url caqn be found for each page its like ths for all the inner pages...........

Thank you.