Extend XSitePro with htaccess
Need to use PHP code on HTML pages? Need to redirect an old page to a new page? Want to use a custom error
page?
.htaccess is your answer.
.htaccess has nothing to do with XSitePro, but with your hosting server. Basically, it tells your server what to
do with certain pages when a browser or bot visits your site.
To use this, create a plain text file, and call it htaccess.txt. The actual file is .htaccess, but Windows by
default will hide all files beginning with a dot, as they are hidden files. So we will start with calling it a text
file, then rename it when adding it to XSitePro. It goes in the ROOT folder of your server.
Once you have the file, here are some codes you can put in your htaccess file.
NOTE: .htaccess is a powerful file. Use with caution, and always check if you already have one first. If
you already have one, edit that one.
Redirect to a new domain
RewriteEngine on
rewritecond %{http_host} ^youroldsite.com[nc]
rewriterule ^(.*)$ http://www.yournewsite.com/$1 [r=301,nc]
Change url to your own.
Redirect to custom error page
ErrorDocument 404 /YourNotFound.html
ErrorDocument 403 /YourForbidden.html
ErrorDocument 500 /YourServerError.html
Change page to your own page name.
Redirect to old page to new page
Redirect 301 /oldpage.php http://www.yoururl.com/newpage.php
Change oldpage.php to your old page name and the url to your new url for the page.
Parse PHP on HTML:
Leave your pages as HTML, and set your server to treat HTML pages the same as PHP pages.
This will enable you to run any needed PHP code, without losing the rank of your pages by changing all the files to
PHP.
AddHandler application/x-httpd-php .html .htm
or
AddHandler application/x-httpd-php5 .html .htm
or if your running Godaddy
AddType application/x-httpd-php .htm .html
AddHandler x-httpd-php .htm .html
Your site will now be able to use PHP code on HTML websites.
Avoid Duplicate Content
Telling all browsers to send all visits to the non www to go to the www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,L]
Change URL to your own.
Protect your .htaccess file
If you use .htaccess to block this, or redirect pages, you should also protect the file from being viewed by
nosey visitors.
<files .htaccess>
order allow,deny
deny from all
</files>
Turn off directory indexing
If you do not have an index file in a folder, browsers can view a list of all files in the folder. Not very
secure. Turn of indexing.
Options -Indexes
Stop Hot Linking
Got some cool images on your site, only to find out people are using them on your site, AND using your
bandwidth? Stop them from linking to files on your server by shutting down hotlinking.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yoursite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^https://(www\.)?yoursite.com/.*$ [NC]
RewriteRule .*\.(jpg|png|bmp)$ - [F,NC]
Change url to your own. and change file types to ones you want to stop hotlinking.
|