tags:

views:

28

answers:

3

Hi folks,

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!

JG

+1  A: 

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.

highphilosopher
Thank you for the reply! When I replace my rule for yours I get the internal server error; if I comment out just the rule like #RewriteRule ^(.*)$ /microsites/index.php?uID=$1 [L] the error goes away same as with my rule.
jerrygarciuh
However the following works and does not throw and error?! RewriteRule ^([0-9])$ /microsites/index.php?uID=$1 [L]
jerrygarciuh
+1  A: 

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]
Gumbo
A: 

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

Dan Beam