mod rewrite: domain.com/folder to domain.com

Using a single web hosting account to host multiple sites

mod rewrite: domain.com/folder to domain.com

Postby joeld » Tue Jul 17, 2007 3:24 am

I host my default site in a subfolder in public_html
I use this mod_rewrite do redirect requests from domain.com to domain.com/folder in .htaccess:

Code: Select all
<IfModule mod_rewrite.c>
   # Turn on rewrites.
   RewriteEngine on
   
   # Only apply to URLs on this domain
   RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
   
   # Only apply to URLs that aren't already under folder.
   # RewriteCond %{REQUEST_URI} !^/folder/
   
   # Don't apply to URLs that go to existing files or folders.
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   
   # Rewrite all those to insert /folder.
   RewriteRule ^(.*)$ folder/$1
   
   # Also redirect the root folder.
   RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
   RewriteRule ^(/)?$ domain.com/index.php [L]
</IfModule>


But the links of my site are: domain.com/folder/link.html
I need to change it to domain.com/link.html

What I'm need to change in .htaccess to get it to work?
joeld
 
Posts: 1
Joined: Mon Jul 16, 2007 6:40 pm

Postby richardk » Wed Jul 18, 2007 7:17 am

Mod_rewrite does not change the links in your pages, it works on the incoming requests only. You have to edit them manually.

This will stop it looping if you go to /abc.php and /folder/abc.php does not exist.
Code: Select all
Options +FollowSymLinks

<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
  # Don't loop.
  RewriteCond %{ENV:REDIRECT_STATUS} ^$
  RewriteCond %{SCRIPT_FILENAME} !-f
  # If its /, or
  RewriteCond %{REQUEST_URI} ^/$ [OR]
  # if it's not a real directory carry on.
  RewriteCond %{SCRIPT_FILENAME} !-d
  RewriteRule ^(.*)$ /folder/$1 [QSA,L]
</IfModule>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 13 guests

cron