homepage Welcome to WebmasterWorld Guest from 54.197.94.241
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
html to php
Jon12345




msg:4270654
 6:09 pm on Feb 22, 2011 (gmt 0)

I have an established site where I had an html homepage for years. Probably loads of links pointing there. Now, I have changed the homepage from index.html to index.php.

What do I need to do to:

a) ensure all index.html traffic gets to the index.php page

b) reduce loss of link juice due to the html to php change

Thanks,

Jon

 

g1smd




msg:4270673
 6:41 pm on Feb 22, 2011 (gmt 0)

Add the
DirectoryIndex index.php directive.

Redirect requests for
/index.php and /index.html to www.example.com/ with a trailing slash.

Link only to
www.example.com/ with a trailing slash within the site.



DirectoryIndex index.php
#
RewriteEngine On
#
# Externally redirect only direct client requests for /index.php to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index.(html?|php)\ HTTP/
RewriteRule ^(([^/]+/)*)index.(html?|php)$ http://www.example.com/$1 [R=301,L]
#
# Externally redirect to canonicalize the domain name if a non-canonical
# hostname is requested, in order to prevent duplicate-content problems
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Jon12345




msg:4270679
 6:52 pm on Feb 22, 2011 (gmt 0)

Thanks for that! Two questions:

1. Am I right in thinking that because I am using a 301 redirect, I will lose a little link juice from the links that previously pointed to index.html?

2. Why would you redirect the php too?

g1smd




msg:4270700
 7:38 pm on Feb 22, 2011 (gmt 0)

1. You lose a little bit of the
/index.html link benefit, but you combine all of the benefits of links pointing at both /index.html and / into one pot. You also use the "preferred" root URL for the site - the URL ending with a trailing slash.

2. Redirect the
.php to / too, otherwise you are promoting duplicate content - the same content at two different URLs. That's also why non-www redirects to www. That fixes another duplication.
Jon12345




msg:4270714
 8:05 pm on Feb 22, 2011 (gmt 0)

So in other words, the upshot of all this is that I might get a ranking boost?

I mean I am sure some of my links are mydomain.com and others www.mydomain.com, some pointing to mydomain.com/index.html and all the other permutations.

Its been fairly nerve-racking turning my static html old-fashioned site into Wordpress. I just hope Google loves the Wordpress format a little more.

g1smd




msg:4270724
 8:30 pm on Feb 22, 2011 (gmt 0)

Make sure you check out a thread elsewhere in this forum which details a new
.htaccess file for Wordpress with a lot of further optimisations.
Jon12345




msg:4270725
 8:35 pm on Feb 22, 2011 (gmt 0)

Thanks for the suggestion. I forgot how high the level of advice was on here.

Jon12345




msg:4270727
 8:38 pm on Feb 22, 2011 (gmt 0)

One last question. I have the following code in my .htaccess already:

# BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
AddOutputFilterByType DEFLATE text/css application/x-javascript text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon
</IfModule>
<FilesMatch "\.(css|js)$">
FileETag None
<IfModule mod_headers.c>
Header set X-Powered-By "W3 Total Cache/0.9.1.3"
</IfModule>
</FilesMatch>
<FilesMatch "\.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$">
FileETag None
<IfModule mod_headers.c>
Header set X-Powered-By "W3 Total Cache/0.9.1.3"
</IfModule>
</FilesMatch>
<FilesMatch "\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3
|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif
|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$">
FileETag None
<IfModule mod_headers.c>
Header set X-Powered-By "W3 Total Cache/0.9.1.3"
</IfModule>
</FilesMatch>
# END W3TC Browser Cache

# BEGIN W3TC Page Cache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} (2\.0\ mmp|240x320|alcatel|amoi|asus|au\-mic|audiovox|avantgo|benq|bird|blackberry|blazer|cdm|cellphone|danger
|ddipocket|docomo|dopod|elaine/3\.0|ericsson|eudoraweb|fly|haier|hiptop|hp\.ipaq|htc|huawei
|i\-mobile|iemobile|j\-phone|kddi|konka|kwc|kyocera/wx310k|lenovo|lg|lg/u990|lge\ vx|midp
|midp\-2\.0|mmef20|mmp|mobilephone|mot\-v|motorola|netfront|newgen|newt|nintendo\ ds
|nintendo\ wii|nitro|nokia|novarra|o2|openweb|opera\ mobi|opera\.mobi|palm|panasonic|pantech|pdxgw
|pg|philips|phone|playstation\ portable|portalmmm|ppc|proxinet|psp|pt|qtek|sagem|samsung|sanyo
|sch|sec|sendo|sgh|sharp|sharp\-tq\-gx10|small|smartphone|softbank|sonyericsson|sph|symbian
|symbian\ os|symbianos|toshiba|treo|ts21i\-10|up\.browser|up\.link|uts|vertu|vodafone|wap|willcome
|windows\ ce|windows\.ce|winwap|xda|zte) [NC]
RewriteRule .* - [E=W3TC_UA:_low]
RewriteCond %{HTTP_USER_AGENT} (acer\ s100|android|archos5|blackberry9500|blackberry9530|blackberry9550|cupcake|docomo\ ht\-03a|dream
|htc\ hero|htc\ magic|htc_dream|htc_magic|incognito|ipad|iphone|ipod|lg\-gw620|liquid\ build|maemo|mot\-mb200|mot\-mb300|nexus\ one|opera\ mini|samsung\-s8000|series60.*webkit
|series60/5\.0|sonyericssone10|sonyericssonu20|sonyericssonx10
|t\-mobile\ mytouch\ 3g|t\-mobile\ opal|tattoo|webmate|webos) [NC]
RewriteRule .* - [E=W3TC_UA:_high]
RewriteCond %{HTTPS} =on
RewriteRule .* - [E=W3TC_SSL:_ssl]
RewriteCond %{SERVER_PORT} =443
RewriteRule .* - [E=W3TC_SSL:_ssl]
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule .* - [E=W3TC_ENC:.gzip]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{REQUEST_URI} \/$
RewriteCond %{REQUEST_URI} !(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register
|mail)\.php|wp-.*\.php|index\.php) [NC,OR]
RewriteCond %{REQUEST_URI} (wp-comments-popup\.php|wp-links-opml\.php|wp-locations\.php) [NC]
RewriteCond %{HTTP_COOKIE} !(comment_author|wp-postpass|wordpress_\[a-f0-9\]\+|wordpress_logged_in) [NC]
RewriteCond "/home/access/public_html/wp-content/w3tc/pgcache/$1/_index%{ENV:W3TC_UA}%{ENV:W3TC_SSL}.html%{ENV:W3TC_ENC}" -f
RewriteRule (.*) "/wp-content/w3tc/pgcache/$1/_index%{ENV:W3TC_UA}%{ENV:W3TC_SSL}.html%{ENV:W3TC_ENC}" [L]
</IfModule>
# END W3TC Page Cache

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


Do I paste in your recommended code above or below that?

[edited by: jdMorgan at 4:51 pm (utc) on Mar 8, 2011]
[edit reason] Fixed side-scroll. [/edit]

g1smd




msg:4270741
 9:05 pm on Feb 22, 2011 (gmt 0)

It likely goes immediately before the Page Cache code.

Add a blank line AFTER every RewriteRule (but only when the next line is a RewriteCond) to make the code more readable.

Remove the repetition of:
RewriteEngine On
RewriteBase /

Jon12345




msg:4270748
 9:21 pm on Feb 22, 2011 (gmt 0)

So between these two?

# END W3TC Browser Cache

# BEGIN W3TC Page Cache

g1smd




msg:4272020
 4:04 am on Feb 25, 2011 (gmt 0)

Yes.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved