Jump to content

Apache Configuration - RewriteRule at Document Root


Recommended Posts

Hello,

 

On my server, I am trying to make it so that the "name" parameter is passed to a file called "profile.php" using RewriteRule. Unfortunately, my skills with this and regular expressions are greatly lacking. Here is what I presently have:

 

RewriteEngine on
RewriteRule ^/([A-Za-z0-9]+)                     profile.php?name=$1                     [NC]

 

What I am wanting to do is this: If a user visits http://mydomain.com/andrew it would appear to PHP as profile.php?name=andrew, unless a file in the directory has that name. I needed to do this as alphanumeric, with capitol characters allowed, and only six characters, but the above code is all I could scrap together, and it doesn't work well at all.

 

Thank you for reading, and for any help,

Shadow Jolteon

I get the same result removing the slash.

 

The problem here is that it doesn't seem to care whether or not the file fits those rules. If they do, it passes the name parameter to the profile.php file, otherwise it just redirects it to the file without the parameter. What I would prefer it to do would be if it does not fit the rules, to display a file that has that name as it normally would.

 

Thanks for the reply!

 

Ps. Nice kemonomimi avatar. ^^

I finally figured it out!

 

Here's what I did, it doesn't do the six characters or less thing I wanted, but for what I'm using it for it will work for now:

RewriteEngine On
RewriteRule ^(.[A-Za-z0-9]+)$       profile.php?name=$1 [NC]

 

Thank you again for the reply! ^^

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.