Avatar of dward81
dward81
 asked on

How Would I Rewrite This URL Using Mod Rewrite?

Apache Web ServerPHP

Avatar of undefined
Last Comment
dward81

8/22/2022 - Mon
Arasian

You need to look at .htaccess files.  An .htaccess file modifies the directory it exists in and any directories under it.  So you would put yours in your root level web directory (http://www.trytlc.com)

Within this .htaccess file, you'd write the following (I don't have a way to test this at the moment but I'm pretty sure this will work)
RewriteEngine On
RewriteRule dward\/(.*)$ http://www.trytlc.com/$1?user=dward [L]

Open in new window

dward81

ASKER
Thank you veyr much for the help. The only problem I have now is that the dward part of the url is dynamic and can change with every user. So how would I modify this to reflect that.

RewriteEngine On
RewriteRule dward\/(.*)$ http://www.trytlc.com/$1?user=dward [L]
Arasian

What you'll have to do is say (pseudocode)
http://www.trytlc.com/USER/FILE = www.trytlc.com/FILE?user=USER.  The problem with that, though is that kills all your real subdirectories in your domain.  So you'll have to have some kind of user delimiter (frequently a tilde), which will make it www.trytlc.com/~dward/FILE.

Your other option is www.trytlc.com/users/dward/FILE.

Which one would you like the script for?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
dward81

ASKER
I think the delimeter with the tilde would be the best bet for my application.

www.trytlc.com/~dward/FILE
ASKER CERTIFIED SOLUTION
Arasian

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Arasian

Ahhh, add an [L] on the end as in the first example.
dward81

ASKER
Thank You very much for the help. I appreciate it greatly.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.