Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Apache RewriteRule for clean url problem

Apache RewriteRule for clean url problem
Thread Tools
Fresh-Faced Recruit
Join Date: Aug 2003
Status: Offline
Reply With Quote
Aug 15, 2003, 10:16 AM
 
The MacNN community has been great in the past for helping me get past problems, so I hope it can do so again.

I am trying to set up a dynamic website to show clean urls using RewriteRule in Apache. I want the url to look like this:

www.site.com/variable1/variable2/variable3

and the page to be served from
www.site.com/variable1?id=variable2&sid=variable3

The problem is that, some of the pages only have variable1 and variable2, but some have three. And I may add a third to the ones that only have two later. Here is what I have in my .htaccess file:

RewriteEngine on
Options +FollowSymlinks
RewriteBase /

RewriteCond %{REQUEST_URI} !^/pdf
RewriteRule ^(.*)/(.*)/?(.*) $1?id=$2&sid=$3

The problem is that I cannot get the third variable to pass through. I have also tried

RewriteRule ^(.*)/(.*)/?(.*)$ $1?id=$2&sid=$3

Is there an easy way to write this?
     
plazmyd  (op)
Fresh-Faced Recruit
Join Date: Aug 2003
Status: Offline
Reply With Quote
Aug 15, 2003, 10:53 AM
 
I think I found a regular expression that does the job:

RewriteRule ^([_a-zA-Z]*)/([_a-zA-Z]*)/?([_a-zA-Z]*)$ $1?id=$2&sid=$3

I don't know why the first way with just the '.'s did not work. Maybe someone could still explin that so I will know.
     
Mac Elite
Join Date: May 2001
Status: Offline
Reply With Quote
Aug 16, 2003, 12:53 AM
 
Originally posted by plazmyd:
I think I found a regular expression that does the job:

RewriteRule ^([_a-zA-Z]*)/([_a-zA-Z]*)/?([_a-zA-Z]*)$ $1?id=$2&sid=$3

I don't know why the first way with just the '.'s did not work. Maybe someone could still explin that so I will know.
I can't explain that, but maybe something like [^/] instead of [_a-zA-Z] would work better for you.

-
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:18 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2