Error » Search Engines » Search Engine Optimization » .htaccess tips

Search Engine Optimization search engine optimization discussion.

Post New Thread Reply
  .htaccess tips
LinkBack Thread Tools Display Modes
Old 28-Dec-2006, 04:57 AM   #1 (permalink)
Administrator
 
Anilrgowda's Avatar

Posts: 18,715
Join Date: Jan 2006
Rep Power: 10 Anilrgowda is on a distinguished road

IM:
Default .htaccess tips

Below I show some common uses of .htaccess which I use myself on many sites. Many of you will find no new information here, but hopefully it will help some!


Code:
Options -Indexes This causes the importat not to list the contents of directories (when there is no index). This keeps people from typing in http://www.example.com/images/ (or any other directory) and getting a list of the files.


Code:
AddType application/x-httpd-php .php .htmThis code tells your server to process PHP code in files with the .htm extension. Some servers allready do this by default, but many do not. You can also add .html to the end (or any other extension) if you like. This will keep you from having to rename files to php if you add scripts in later, and also I just happen to like it more


Code:
ErrorDocument 400 /errors/400.htm
ErrorDocument 401 /errors/401.htm
ErrorDocument 403 /errors/403.htm
ErrorDocument 404 /errors/404.htm
ErrorDocument 500 /errors/500.htm The control panel of many hosts let you set the custom error pages, but doing it directly is just as easy. I use these 5 common ones. Just create your pretty error pages, and point to them in .htaccess.


Code:
redirectPermanent /somepage.htm http://www.example.com/index.htmJust a basic redirect example here. For when you get rid of a page and want all links to it to just point to the index.


Code:
redirectMatch 301 ^/old_directory/(.*) http://www.example.com/index.htmHere we get a little fancier. This is for when you remove an entire directory. It will make any link to that directory (including all pages and sub-pages in it) go back to your main index.


Code:
redirectMatch 301 ^/subsite/(.*) http://www.example.com/$1
redirectMatch 301 ^/subsite http://www.example.com/$1Say you have a sub-site on your domain.. in the 'subsite' directory, and you moved it to its own [COLOR=green ! important][COLOR=green ! important]domain[/color][/color]. These two redirects will take all possible link combinations and redirect them to the new domain. Even if the link is like this : /subsite/1/2/3/4/index.php it will redirect to www.example.com/1/2/3/4/index.php. The two lines give you better flexibility. It handles all combinations of trailing slashes, directories/files, and www. prefixes.


Code:
Options +FollowSymLinks
RewriteEngine onThis code gets the server ready for the next few things we will do


Code:
RewriteCond %{HTTP_HOST} ^example.(.*)
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] This bit of code is quite usefull. It will take any links that do not have www in them, and add it to the URL. This means no matter how they link to you, your full domain (with the www) will get the backlink.


Code:
RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.example.com/index.htm [R,NC]This is basic hot-link protection code. I did have two other lines added to it (to take care of the times when the link does not contain the www) but if you use the last tip, you do not have to worry about it. Just make sure to put them in order (so the www gets added before the hot-link protection). This will only allow hot-linking from your site. If you want to add another site, just add the appropriate lines.

Now if you want to sometimes allow hot-linking, here is a good method. Create a directory called 'share' (or whatever) and stick in a new .htaccess file with only this line:


Code:
RewriteEngine offThis will counter-act the global .htaccess, and allow hot-linking from whatever directory you stick it in (and sub-directories)
Anilrgowda is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
   


   
Post New Thread Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -8. The time now is 02:27 AM.

Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0

DMCA Policy

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228