Development Blog by Professionals
Posts tagged .htaccess
.htaccess SSI Variables
Jul 22nd
SSI Variables
DATE_GMT=Sun Mar 8 22:58:56 2009 DATE_LOCAL=Sun Mar 8 15:58:56 2009 DOCUMENT_NAME=FOOTER.html DOCUMENT_ROOT=/root-srv/protected/askapache.com/sec DOCUMENT_URI=/includes/FOOTER.html GATEWAY_INTERFACE=CGI/1.1 HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 HTTP_ACCEPT_CHARSET=ISO-8859-1,utf-8;q=0.7,*;q=0.7 HTTP_ACCEPT_ENCODING=gzip,deflate HTTP_ACCEPT_LANGUAGE=en-us,en;q=0.5 HTTP_CACHE_CONTROL=max-age=0 HTTP_CONNECTION=keep-alive HTTP_COOKIE=__qca=12298910-686528-46510; __utmb=50625.1.0.11311 HTTP_HOST=www.askapache.com HTTP_KEEP_ALIVE=300 HTTP_REFERER=http://www.askapache.com/htaccess/htaccess.html HTTP_USER_AGENT=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6 (.NET CLR 3.5.30729) LAST_MODIFIED=Sun Mar 8 14:53:50 2009 PATH=/bin:/usr/bin:/sbin:/usr/sbin QUERY_STRING= REMOTE_ADDR=24.123.215.60 REMOTE_PORT=4785 REQUEST_METHOD=GET REQUEST_URI=/htaccess/ SCRIPT_FILENAME=/root-srv/protected/askapache.com/sec/includes/FOOTER.html SCRIPT_NAME=/includes/FOOTER.html SCRIPT_URI=http://www.askapache.com/htaccess/ SCRIPT_URL=/htaccess/ SERVER_ADDR=64.111.114.111 SERVER_ADMIN=webmaster@askapache.com SERVER_NAME=www.askapache.com SERVER_PORT=80 SERVER_PROTOCOL=INCLUDED SERVER_SIGNATURE= SERVER_SOFTWARE=Apache/2.0.61 (Unix) PHP/4.4.7 mod_ssl/2.0.63 OpenSSL/0.9.7e mod_fastcgi/2.4.2 DAV/2 SVN/1.4.2 UNIQUE_ID=dnbtH0Bvcm8A2ZHqcAAAAM USER_NAME=
More SSI Information
How to enable or use .htaccess on Apache Web Servers in Windows:
May 5th
- Using a text editor, open the httpd.conf file. In XAMPP, this file is found in the \apache\conf directory
- Locate the following line of code:
#LoadModule rewrite_module modules/mod_rewrite.so
- Remove the # from the line as seen below to enable the module:
LoadModule rewrite_module modules/mod_rewrite.so
- Save the httpd.conf file and Restart your server
- Restart your Apache Server
If all goes well, you should now be able to use .htaccess files.
How to Redirect a Web Page
Aug 8th
301 Redirect
301 redirect is the most efficient and Search Engine Friendly method for webpage redirection. It’s not that hard to implement and it should preserve your search engine rankings for that particular page. If you have to change file names or move pages around, it’s the safest option. The code “301″ is interpreted as “moved permanently”.
You can Test your redirection with Search Engine Friendly Redirect Checker
Below are a Couple of methods to implement URL Redirection More >
301 Redirect Examples .htaccess
Aug 8th
To Move a single page
Quick, easy and seamless for your visitors.
Redirect 301 /oldpage.html http://www.example.com/newpage.html
To Move an entire site
This will catch any traffic on your old site and redirect it to your index page on your new server. If you want to redirect each page to its new spot, this isn’t the one for you.
Redirect 301 / http://www.example.com/
Changed file extension?
This example is perfect if you’ve decided to switch to .php from .html pages. It will look for any .html page and redirect it to .php (ie http://www.example.com/yourpage.html and redirect it to http://www.example.com/yourpage.php). Now, be careful with this, it does mean any html page. I did this on one of my sites and had totally forgotten I had an iframe with .html content on some pages… I didn’t notice for weeks that it was broken :S.
So learn from my mistake
check, double check, then check again.
RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php
Redirect www to non www version of site .htaccess
Aug 6th
Redirect www to non www version of site
It’s best to stick with either always using www.example.com or just example.com. Allowing both can confuse the search engines. So here’s how to force your site to always show the non-www version. (Search for “canonical url errors” in your favorite search engine for more info.)
Note: If you do use either of the next 2 codes below, and use a secure server (ie. https:) be sure to check that it doesn’t redirect the secure to the insecure version. I’m pretty sure this will do that and that isn’t something you want!
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L]
Redirect non-www to www
Same as above except in the reverse, this one forces the www. into your url.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]


