Please Help me in htaccess file mod_rewrite + redirect

Discussion in 'PHP' started by webmaster365, Jun 7, 2010.

  1. #1
    This is my .htaccess file and working fine.
    What I want If any one try to browse the site without www , this have the capability to redirect the url with www.

    Example:- if someone try to browse with
    http://mydomain.com/theater/city/123
    then this will be redirect to
    http://www.mydomain.com/theater/city/123

    My current .htaccess file below.

    Options +FollowSymLinks
    Options -MultiViews
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteRule \.(gif|jpg)$ - [F]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    
    RewriteRule ^city/(.*)/(.*)$  index.php?city=$1&page=$2 
    RewriteCond %{QUERY_STRING} !page
    RewriteRule ^city/(.*)$       index.php?city=$1 [L]
    
    
    
    RewriteRule ^cinemas/(.*)/(.*)/(.*)$    theater.php?thid=$3&cityname=$1 [L] 
    RewriteRule ^cinemas-new/(.*)/(.*)/(.*)$    theater-new.php?thid=$3&cityname=$1 [L]	
    RewriteRule ^sitemap.xml(.*)$           sitemap.php [L]  
    Code (markup):

    Thanks in advance I really require this.
     
    webmaster365, Jun 7, 2010 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    
    # force www. start
    RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com [NC]
    RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L] 
    # force www. stop
    
    Code (markup):
     
    stephan2307, Jun 8, 2010 IP
  3. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #3
    Here it goes

    
    Options +FollowSymLinks
    Options -MultiViews
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^domain.com [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
    RewriteCond %{HTTP_REFERER} !^$
    RewriteRule \.(gif|jpg)$ - [F]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    
    RewriteRule ^city/(.*)/(.*)$  index.php?city=$1&page=$2 
    RewriteCond %{QUERY_STRING} !page
    RewriteRule ^city/(.*)$       index.php?city=$1 [L]
    
    
    
    RewriteRule ^cinemas/(.*)/(.*)/(.*)$    theater.php?thid=$3&cityname=$1 [L] 
    RewriteRule ^cinemas-new/(.*)/(.*)/(.*)$    theater-new.php?thid=$3&cityname=$1 [L]	
    RewriteRule ^sitemap.xml(.*)$           sitemap.php [L]
     
    
    Code (markup):
     
    roopajyothi, Jun 8, 2010 IP
  4. webmaster365

    webmaster365 Greenhorn

    Messages:
    86
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    Hello All,

    I am really thanks to u all, otherwise I have to do struggle a lot to achieve the same.
     
    webmaster365, Jun 10, 2010 IP