ncla
ncla

Reputation: 811

Multiple rewrite_rules

I am having a hard time getting two rewrite rules to work. Right now these links do work:

http://domainname.com/blog/something/something/andsomethingelse/
http://domainname.com/blog/
http://domainname.com/leaderboard/

If I access, /leaderboard/something, it shows Not Found error page from WordPress blog, ignoring the leaderboard rewrite rule.

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /leaderboard/index.php [L]

Upvotes: 1

Views: 94

Answers (3)

sNuuFix
sNuuFix

Reputation: 26

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

# Ignore real files/folders
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .? - [L]

RewriteRule ^blog/(.+?)$ /blog/index.php [L] # WP standard syntax
RewriteRule ^leaderboard/(.+?)$ /leaderboard/index.php?var=$1 [L]

Upvotes: 1

Get Off My Lawn
Get Off My Lawn

Reputation: 36351

I believe this may be what you're looking for.

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^blog/(.+)$ /blog/index.php?path=$1
RewriteRule ^leaderboard/(.+)$ /leaderboard/index.php?path=$1

Then you can access the pages like so:

http://domain.com/blog/something/somethingelse
http://domain.com/leaderboard/something/somethingelse

and in the background it would look like this:

http://domain.com/blog/index.php?path=something/somethingelse
http://domain.com/leaderboard/index.php?path=something/somethingelse

Upvotes: 0

ops
ops

Reputation: 2049

You should write rewrite_rules like this code:

RewriteRule (.*)/(.*)/(.*)/(.*)$ index.php?var1=$1&var2=$2&var3=$3&var4=$4 [L]

Your writing code matches anything.

Upvotes: 0

Related Questions