wordpress: exclude directory from rewrite rule

Discuss practical ways rearrange URLs using mod_rewrite.

wordpress: exclude directory from rewrite rule

Postby dreamcube » Sun Aug 03, 2008 4:33 pm

In order for wordpress to use SEF URL's it uses the following rule in the .htacess file:

RewriteBase /
RewriteRule . /index.php [L]

I have a file that is outside the theme folder (in the web root) that I want to use SEF URLs as well. Here is the rule that I have

RewriteRule ^profiles/([A-Za-z0-9-]+)/?$ profiles.php?name=$1 [L]

These two clash. I have tried numerous diff methods and even took a trip to the bookstore to no avail. Hopefully someone here can help :).

How can I exclude the second rewrite from the first rule and allow it to work?

Thanks,
Tom
dreamcube
 
Posts: 3
Joined: Sun Aug 03, 2008 4:30 pm

Nebermind

Postby dreamcube » Sun Aug 03, 2008 4:52 pm

I found what I was looking for:

viewtopic.php?t=4727&highlight=wordpress

effin n00bs.

Well, Hi everybody, I think I will be spending some time here for a while as a lot of my upcoming projects can benefit from a better understanding of mod_rewrite.

As I mentioned, I tried to find a good book on Apache or even .htacess would be better.... any recommendations?
dreamcube
 
Posts: 3
Joined: Sun Aug 03, 2008 4:30 pm

Postby dreamcube » Mon Aug 04, 2008 5:23 pm

Ran into a new problem...

What if I have a php page that is handling 2 session variables and sometimes the second variable will be null.

For example

url could be
http://www.mysite.com/a/

or

http://www.mysite.com/a/anderson/

I'm using:

RewriteRule ^profiles/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ profiles.php?letter=$1&fullname=$2 [L]

But this won't work if I only have one variable to pass.
dreamcube
 
Posts: 3
Joined: Sun Aug 03, 2008 4:30 pm

Postby richardk » Wed Aug 06, 2008 3:17 pm

Try
Code: Select all
^profiles/([A-Za-z0-9-]+)(?:/([A-Za-z0-9-]+))?/?$

The surrounding ()? makes the last /([A-Za-z0-9-]+) optional.
?: matches the () not create a backreference (variable) so $2 is still for the second ([A-Za-z0-9-]+).
richardk
 
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 106 guests

cron