Previously I wrote Rewriting tips using .htaccess file for URL rewriting.
Common Usage of .htaccess file :
– Authorization, authentication
– Rewriting URLs
– Blocking
– Directory listing
– MIME types
– Cache Control, and many more.
Here is a test to check that .htaccess or mod_rewrite is enabled on any type of hosting whether shared or dedicated.
Now we want to check for mod_rewrite is enabled or not.
1- First of all create an empty file and name it test.html (or what you want) and upload this file on you hosting server.
2- Create a .htaccess file and put the following code into it. (create htaccess.txt file )
[php]
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^test\.html http://www.google.com/? [R=301,L]
[/php]
Note: On windows machine first create htaccess.txt file, then adds the above code into it, upload on server, after uploading remove the .txt extension.
3- Now run this URL into your browser http://www.domain-name.com/test.html (replace domain-name.com with your actual domain name).
If it redirects you on google.com then mod_rewrite is working on your server host, if it is not, shows you a blank file means mod_rewrite is not working.
4- If your site runs in some folder then adds the folder name before test.html and uploads the htaccess file in the root folder. Eg
[php]
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^foldername/test\.html http://www.google.com/? [R=301,L]
[/php]
طراحی سایت
http://www.sanadata.com
Read was interesting on several columns. Thank you
Thanks for the article. I followed your suggestion, but my test.html is not rediercted to google.com. I have restarted the apache service, using the command sudo service httpd restart. Then how to enable or make .htaccess to work on my site.
To enable using a .htaccess file, change AllowOverride None to AllowOverride All.
For example,
httpd.conf before:
Options FollowSymLinks
AllowOverride None
httpd.conf after:
Options FollowSymLinks
AllowOverride All
Thank you Amerandra. I have been struggling for some time to get mod_rewrite in apache to work, so that BuddyPress and WordPress would work. I had a case of the dreaded 404 for all BuddyPress links. I finallly determined that my .htaccess file was not being used. But I still didn’t know why! mod_rewrite was enabled so that was not it.
AllowOverride All was the key variable I needed. Ah, sweet success.
Thanks Man