Home > DeveloperSection > Forums > Rewrite URL www.domain.com causing 404 on my page
Chintoo Semi

Total Post:135

Points:947
Posted on    April-10-2013 1:40 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 898  View(s)
Rate this:
Hi Everyone!

Ok so I've rewrited URL in my website, now for some reason, it is throwing 404 error if I type www.domain.com, if I type domian.com, everything works fine.

DirectoryIndex home.php

IndexIgnore *
#RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
#RewriteRule ^(.*)$ http://%1/directory/$1 [L,R=301]

RewriteRule ^home/?$   home.php  [NC]
RewriteRule ^about/?$   about.php  [NC]

RewriteRule ^404/?$   404.php  [NC]

ErrorDocument 404 http://domain.com/directory/404
Note: I've commented the 1st 2 rewrite rules as even If I change them it doesn't effect after uploading .htaccess to server, feels like it's cached.

Additional Info, am using <base> tag which is in embeds.php

if($_SERVER['REMOTE_ADDR'] == '::1') {
    echo '<base href="http://localhost/projects/directory/" />';
} else {
    echo '<base href="http://domain.com/directory/" />';
}
Directory Structure

Root -
  home.php
  about.php
     -stylesheets
      default.css
     -includes
      embeds.php
  404.php
  .htaccess
embeds.php is included in home.php, about.php etc, and stylesheets, scripts etc, inshort the head section along with <base> tag are in embeds.php

Thanks  you in advance!



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    April-15-2013 7:49 AM

Hi Chinto!

Try as below

RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^(.*) http://www.domain.com/$1  [QSA,L,R=301]

It should work, if it dosn't it comes from your DNS, or Vhost configuration.

Don't want to miss updates? Please click the below button!

Follow MindStick