We use .htaccess to rewrite and redirect link. When you get your new hosting its always there is easy step to verify if .htaccess is working fine or not on your new hosting account. Some hosting does not configure their apache server correctly and caused .htaccess is not working even the code itself is correct. So, Here is simple step that might useful for you to verify if the .htaccess is work or not working. (with these instruction, make sure you have root access to your server)
First of all you will need to check if mod_rewrite is enabled for apache.
cat /etc/httpd/conf/httpd.conf | grep rewrite
make sure you see result below:
LoadModule rewrite_module modules/mod_rewrite.so
if you dont see above line, then you will need to add it. If yes you can proceed to 2nd step
make sure AllowOverride inside httpd.conf is set to All instead of none by default.
example show on below:
Options FollowSymLinks
AllowOverride none
change to :
Options FollowSymLinks
AllowOverride All
Dont forget to restart apache after making change to AllowOverride. /var/www/html is example of mine, you can replace it to your directory example: /home/user/public_html
What next? Test it!!
Open notepad and copy and paste the following code into it:
<?php // htaccess tester // Copyright 2011 Booser if($_GET['url']==1){echo "Damn it! looks like htaccess is not working, please refer to: Booser Verify Htaccess for solution";} elseif($_GET['url']==2){echo" YES!! Your .htaccess is work fine man!";} else{echo"Linux Apache mod_rewrte Test Tutorial";} ?>
LINK1 = rewrite.php?link=1
LINK2 = link2.html
Click on Link1 and Link2, they both are same file, if you clicked link2 not work or get 404 mean its not working you will need to refer Booser Verify htaccess for solution
If you like Booser, you can copy this code and paste it to your website. Verify if .htaccess is working or not
Save it as: rewrite.php
Next step is open a new notepad again and paste following into it:
RewriteEngine On
RewriteRule ^my-rewite-link([^/]*).html$ rewrite.php?url=$1 [L]
Save it as: .htaccess
Now upload both files to your server using ftp, so that you can access it from url:
http://www.yourcoolsite.com/rewrite.php
click on Link1 and Link2 to test them out.
If you get:
404 error its mean, you dont have mod_rewite installed correctly or allowOveride is none.
500 internal error mean that you have some problem with .htaccess files make sure you copy them correctly.
You can contact your hosting to check if you not sure what you are going to do, or drop me a message on contact page, i would happily to check it for you.
Hope that help.
~Cheers~