Learn how to a build a cloud-first strategyRegister Now


Mod rewrite conditional

Posted on 2006-05-05
Medium Priority
Last Modified: 2008-02-01

I'm trying out some stuff with mod rewrite and only have partial success.  I'll give you the problem and show you what I've got and hopefully we can all figure out how to make this work for me = )

I have the site site.com?Site=dynamic_name
When going to different areas of the page I am using site.com?Site=dynamic_name&Ex=New_Command

What I wanted to do is turn that into site.com/dynamic_name and when the second one is called site.com/dynamic_name/New_Command

Make sense?

RewriteCond   %{REQUEST_FILENAME} !-f
RewriteCond   %{REQUEST_FILENAME} !-d
RewriteRule   ^(.*) subsite.php\?Site=$1 [QSA,L]

That gets me the first one so I try to tweak that out a bit to:
RewriteRule ^(.*)-([A-Za-z_\ -]+)\/ subsite.php\?Site=$1&Ex=$2 [QSA,L]

Now I'm running into problems.  I'm sure it will be obvious to those of you with more skills/knowledge of URL rewriting but that's not me = /

Thank you very much for any help you can assist with this.
Question by:gijew
1 Comment

Accepted Solution

funamentalist earned 2000 total points
ID: 16620981
i would probably do it like this.

RewriteRule ^/([0-9a-zA-Z_]+) subsite.php?Site=$1 [L]
RewriteRule ^/([0-9a-zA-Z_]+)/([0-9a-zA-Z_]+) subsite.php?Site=$1&Ex=$2 [L]

hope this helps.

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month20 days, 17 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question