jerrygarciuh
jerrygarciuh

Reputation: 22018

mod_rewrite error

Using this rewrite rule is giving me a 500. What is wrong with my syntax?

Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^microsites/(.*)$ /microsites/index.php?uID=$1 [L]

What I want to do is silently write http://site.com/microsites/anythingatall to http://site.com/microsites/index.php?uID=anythingatall

Edit: the following works and does not throw an error

RewriteRule ^([0-9])$ /microsites/index.php?uID=$1 [L]

// end edit

Thanks for any advice!

Upvotes: 0

Views: 101

Answers (3)

Dan Beam
Dan Beam

Reputation: 3927

Check your rewrite log. I think you're ending up in a rewrite loop, as ^microsites/(.*)$ is matched by the URL you're redirecting to (/microsites/index.php?uID=$1) so it continues to cycle until your max number of internal redirects is met (by default 10)

Try this:

RewriteEngine on
RewriteBase /
RewriteRule ^microsites/([^\.\?]+)$ /microsites/index.php?uID=$1 [L]

which means (in pseudo-code)

if we found a "microsites/" at the beginning
and there are no "." or "?" characters, store this value in $1
then redirect to /microsites/index.php?uID=$1

so the second time around, it will see you've already done the redirect and not loop forever

Upvotes: 0

Gumbo
Gumbo

Reputation: 655785

The mistake is that microsites/index.php is also matched by ^microsites/(.*)$. Exclude your destination and it should work:

RewriteCond $1 !=index.php
RewriteRule ^microsites/(.*)$ /microsites/index.php?uID=$1 [L]

Upvotes: 1

SamuelWarren
SamuelWarren

Reputation: 1459

Try This instead:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /microsites/
RewriteRule ^(.*)$ /microsites/index.php?uID=$1 [L]

It's been awhile, but I believe you need to ensure your base takes care of any actual folder names unless you're going to use them as pieces of your replacement value.

Upvotes: 1

Related Questions