Wednesday 27 November 2013

URL Rewriting in PHP

Apache Module is very difficult but now it come easier for you by using this tutorial or blog for that you will read properly and apply in your website.

For URL Rewriting or Sexy URL you have to start your apache rewrite module from Wamp or XAMP Server following STEPS are as Follows 

Step 1 : First Start Your Wamp/Xamp SERVER .

Step 2 : Now Go For Apache Module in Apache and Find rewrite_module and Click on it . it will show like this : 



Step 3 : Now .htaccess file not .htacces.txt ok .

Step 4 : And Write Code in .htaccess file like this 

1) Start Your Rewrite Engine On by using this code 

RewriteEngine On


2) And Type The following RewriteRule for all the pages 
 RewriteRule ^/(.*) http://www.example.com/$1 [L,R]

3) Now You can also apply Rewrite Condition For Example

# For sites running on a port other than 80
RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://www.example.com:%{SERVER_PORT}/$1 [L,R]

# And for a site running on port 80
RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$


Now Total Solution is : 

RewriteEngine On
# For sites running on a port other than 80
RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://www.example.com:%{SERVER_PORT}/$1 [L,R]

# And for a site running on port 80
RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$

RewriteRule ^/(.*) http://www.example.com/$1 [L,R]



No comments: