.htaccess tutorial

htaccess Elite


Rewrite to ID page & Row (row is optional)

Ask your mod_rewrite and Redirection questions here, and get answers!

Rewrite to ID page & Row (row is optional)

New postby rca » 12 Oct 2009 16:18

Hello,

Just found this forum, google groups htaccess forum is pretty useless, 73 members and no one uses it. :)

I am working on a website where users have the ability to add content in various pages. Posts, Assignments, Resources etc.

I am giving them the ability to name their space giving them a URL of http://server.domain.com/username/

Each of the pages would then follow the URL as http://server.domain.com/username/Posts etc.

I have the below cond/rewrite working.

Code: Select all
# run correct page for each site_id
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9\-]*)/(.*)$ /pages/$2/index.php?site_id=$1 [QSA,L]


Where:
$2 = the page to show... /root/pages/Posts/index.php
$1 = the user site to load

My only problem now is when a visitor/user hits a specific post or a user needs to edit a specific post.

http://server.domain.com/username/Posts/1

I cannot get it to read the next value, it automatically assumes I'm trying to access a directory named Posts/1

I've tried
Code: Select all
RewriteRule ^([a-zA-Z0-9\-]*)/(.*)$/([0-9]*)$ /pages/$2/index.php?site_id=$1&row=$3 [QSA,L]

With no success.

If you can help, I'd really appreciate it.
rca
 
Posts: 2
Joined: 11 Oct 2009 21:25

Re: Rewrite to ID page & Row (row is optional)

New postby rca » 12 Oct 2009 17:26

mulled over it long enough, the answer...

RewriteRule ^([a-zA-Z0-9\-]*)/([a-zA-Z]*)/([0-9]*)/$ /pages/$2/index.php?site_id=$1&row=$3 [QSA,L]
rca
 
Posts: 2
Joined: 11 Oct 2009 21:25


Return to Redirect or Rewrite Questions