views:

39

answers:

1

I need to rewrite any url on my domain that starts with /club/anyPage to /page/club/anyPage.

For this, I believe I can use the following command:

RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]

Also, if the physical page does not exist I want it conditionally rewritten like so:

/club/$1 to /page/club/club.php?title=$1

So in this case if the user enters in mysite.com/club/New_Club they should actually be viewing /page/club/club.php?title=New_Club

+1  A: 

Your original rules seems to work OK for it's job, but to encorporate the second requirement, something like this should do the job...

# do first rule if not file/directory
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^club/([^/]*)$ /page/club/club.php?title=$1 [NC]
# do second rule if not file/directory
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]

or depending on other rules...

# prevent requests for real files / directories from rewritting at all
RewriteCond %{REQUEST_URI} -f
RewriteCond %{REQUEST_URI} -d
RewriteRule .* - [L]

RewriteRule ^club/([^/]*)$ /page/club/$1 [NC]
RewriteRule ^club/([^/]*)$ /page/club/club.php?title=$1 [NC]
Cags
Actually, this works for the second case but not when the file actually exists. So /club/realPage redirects to /page/club/club.php?title=realPage
pws5068
The first two lines here should have been RewriteCond's not RewriteRules, you would also need to duplicated them for the second rule, or refactor.
Cags
I apologize for my ignorance, but could you edit this post to show what you mean by duplicating for the second rule?
pws5068
updated accordingly
Cags