Userdirs With ModRewrite

Discuss practical ways rearrange URLs using mod_rewrite.

Userdirs With ModRewrite

Postby Kay » Mon Nov 03, 2008 7:34 am

Hello people, it's been awhile!

I had to enable userdir in my server for users to host their own pages in the form of "

I wanted to do that by using mod_rewrite and not by enabling the userdir module brought by Apache so I ended up writing this rewrite down in my .htaccess file.

Options +FollowSymLinks
RewriteEngine On
/*The folder the userfiles reside inside my document root
RewriteRule ^(webteam) - [L]
/*Rewriting starts here
RewriteCond %{HTTP_HOST} ^$
/*When this conditions are met
RewriteCond %{REQUEST_URI} !^/~\w+/.*$
/*Then point to this folder inside webteam folder where $1 is the user's name and $2 is index.html
RewriteRule /~(\w+)/(.*) /webteam/$1/public_html/$2
RewriteCond %{REQUEST_URI} !^/~\w+$
RewriteRule /~(\w+) /webteam/$1/public_html/
/*In the beggining if client doesn't choose to enter userdir mode then point to a subfolder named static and hide url formation
RewriteCond %{REQUEST_URI} !^/static/
RewriteRule (.*) /static/$


So far this works smoothly but for one problem.

mod_rewrite userdir works but only for index.html - if index page of user has a link in another page inside his site then it forgots all about rewrite and it points to a file which supposedly resides in

To make things clearer:

A siteuser wants to enter
This is done correctly - the rewrite works and points to
When siteuser click on a link in the user1's index page for instance:
then rewrite malfunctions and it searches secondpage inside

Could we set this right?
Posts: 5
Joined: Fri Jul 25, 2008 4:15 am

Postby richardk » Mon Nov 03, 2008 12:17 pm

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^~(\w+)(/(.*))?$ /webteam/$1/public_html/$3 [QSA,L]

RewriteRule !^(static|webteam)(/.*)?$ /static%{REQUEST_URI} [QSA,L]
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 3 guests