Avatar of lokeshv
lokeshv
 asked on

mod_rewrite question

Hello all

i am using mod_rewrite for rewriting urs

like http://mydomain.com/username

problem is whenever a user enter even valid location on my domain (like images) or any other dir..

which i use for static content..

like http://mydomain.com/statc/

it takes as username also..so how to prevent it ?

i am thinking of to change all dirs names to start with _

so just looking for right .htaccess code to do this..

Thanks in advance
PHP

Avatar of undefined
Last Comment
lokeshv

8/22/2022 - Mon
blue_hunter

maybe you should tweak a bit

like for user
use
http://mydomain.com/user/username

instead of
http://mydomain.com/username

and in your server configuration, you would take whatever appear after "user/" as the user name.

i believe, this would prevent you to getting "static/" as username too
tolgaong


RewriteEngine On
RewriteRule ^user/([a-z]+)/?$ /usercheck.php?username=$1
RewriteRule ^statc/?$ /statistics.php

lokeshv

ASKER
umm

using urls as http://mydomain.com/user/username is certainly not a option...as client doesnt want it ..and application is in last stage.. will have to make lot of changes..

what i am looking for is a regex..for Rewriterule so..part which doesnt start with underscore( _ ) only get rewrited ..

possible ?

Thanks.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
hernst42

Can you post the regex you are currently use?
change the first character of your regex to [^_] this should prevent matching dirs starting with a _
lokeshv

ASKER
Hello

hernst42, currently i use this rule

RewriteRule ^(.*)/$ view.php?tid=$1

very simple..not i wann it convert so only dirs which doesnt start with _ should use this rule...

i tired putting  [^_] in start

http://mydomain.com/_lost/ works fine but when i enter

http://mydomain.com/lokesh it cuts the first chracter and send username to 'okesh' to view .php

how to solve it ?

Thanks for help

ASKER CERTIFIED SOLUTION
hernst42

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
lokeshv

ASKER
works great...

Thaks for help...
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.