Link to home
Start Free TrialLog in
Avatar of davidrobles23
davidrobles23Flag for United Kingdom of Great Britain and Northern Ireland

asked on

URL Mod Rewriting for Directory Slashes

I have a website with user accounts like these: http://www.mywebsite.com/username/

I have this .htaccess file:

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^(.*)/ user.php?uid=$1

It is working fine for urls with the /username/, but when users put the URL in the way http://www.mywebsite.com/username, I get Error 404

I have been trying a lot of RewriteRules, can anyone help me with this?
Avatar of JamesCssl
JamesCssl
Flag of United States of America image

Just add the following rule:
RewriteRule ^/([a-zA-Z0-9_-]+)$ /$1/ [L]

I don't know what characters you allow in your usernames, so it may need to be tweaked slightly.

RewriteRule ^/?([a-zA-Z0-9_-]+)$ /$1/ [L]

allows letters, numbers, an underscore, and a hyphen
ASKER CERTIFIED SOLUTION
Avatar of raheel_lips
raheel_lips

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of raheel_lips
raheel_lips

JamesCssl:... See.
for the images, css and others files, he will handle this from central configuration varaibles which is also recommended by experts. like:

define("fontEndUrl")  = "http://mysite.com/";
define("images")  = fontEndUrl."images";
define("css")  = fontEndUrl."css";

Now developer will include this configuration file on all PHP pages and safely use url for images as follows:
<img src=<?=images?>raheel.jpg border=0 />
 
This simple and easy solution for handle such path issues without involment with .htaccess.

Cheers JamesCssl..... ;)
Avatar of davidrobles23

ASKER

Thanks guys, with all the information I made it work excellent

Thanks again!!