mod rewrite question

bennybutler
bennybutler used Ask the Experts™
on
Ok, I have a mod_rewrite that someone did for me.

Right now, if anyone hits website.com/mynamehere/
And if it doesn't exist, it sends them to
/control.php?reseller=mynamehere

I need it to instead behave like:
website.com/a/mynamehere go to website.com/credit/?aff=mynamehere

I'm just adding a subdirectory, and sending to a different page.  But my regex'n skills don't exist.
RewriteEngine on
       # is not a directory
       RewriteCond /www/wse/$1/ !-d
       # the A-Z is being caught by the NC flag (compiles the regEx case-intensive)
       RewriteRule ^/([a-z0-9_-]+)/$ /$1 [NC,R=301,L]
 
       # is not a directory
       RewriteCond /www/wse/$1/ !-d
       # the A-Z is being caught by the NC flag (compiles the regEx case-intensive)
       RewriteRule ^/([a-z0-9_-]+)$ /control.php?reseller=$1 [NC,L]

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2008

Commented:
> I'm just adding a subdirectory

variable or or a fixed one for all links?
Top Expert 2010
Commented:
Hi

Are the directories also being restructured, so:
/www/wse/myname/
becomes:
/www/wse/aaaa/myname/

Also what OS are you running on as the "!-d" relies on the host file system not being case sensetive.

Oh the following will get you most of the way there:

RewriteEngine on

#If the requested name does not exist as is, see if it exists in lowercase
RewriteMap lowercase int:tolower
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}/  !-d
RewriteCond %{DOCUMENT_ROOT}/${lowercase:%{REQUEST_URI}}/  -d
RewriteRule .*  /${lowercase:%{REQUEST_URI}}  [R=301,L]

#If the directory still does not exist re-direct to an error page
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}/  !-d
RewriteRule /([^/]*/*)([a-z0-9_-]+)/$  /credit/?aff=$1  [NC,R=301,L]

Note: If the new directory name is fixed and 'a' you may want the line above to look like that below:

RewriteRule /a/([a-z0-9_-]+)/$  /credit/?aff=$1  [NC,R=301,L]

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial