Jump to content

is this code correct?


jacko310592

Recommended Posts

hey guys,

 

is the following rewrite rule correct for allowing "mysite.com/user/USERNAME"  from the full address of  "mysite.com/user/index.php?USERNAME

 

#Rewrite URL for User Profile, from /user/index.php?USERNAME to /user/USERNAME
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^user/([a-zA-Z0-9_]+)?$ user/index.php?$1 [NC,L]

 

...it seems to be working fine, but im no good with expressions or rewriting in general so i thought id make sure its 100% fine and with no extra bits that arent needed.

 

oh, and the 'USERNAME' can only be letters (A-Z, a-z), numbers (0-9) and underscores.

 

thanks

Link to comment
Share on other sites

ive decided that i actually need this rewrite code to accept any characters so i can filter incorrect usernames on the actual page, instead of it throwing a 404 error once a username with the wrong characters is entered.

 

so far i have this:

RewriteRule ^profile/(.*)$ profile/index.php?$1 [NC,L]

...but this gives a 403 error if a url with characters such as * " %  are included.

 

can someone please tell me how to change this code to allow any characters to be entered into the username part of the url

 

thanks

Link to comment
Share on other sites

okay, i have another problem now =/

this is the folder structure of /user/....

 

/user/

/user/index.php            <--- this is the index page within the user folder i am wanting to be rewritten

/user/USERNAME1/        <--- each user gets a folder, this folder contains images etc

 

now it seems with the rewrite rule that was suggest above, the images arent being found.

 

can this problem be solved?

 

thanks

 

Link to comment
Share on other sites

Nevermind, it's because you wanted to match ALL characters, therefore 'user/USERNAME/40cabc290f43631cb4a7844790b1f2f8.png' matches and is redirected. Try this instead.

 

RewriteRule ^user/([^/]+)/?$ user/index.php?$1 [NC,L]

Link to comment
Share on other sites

yeah, when i user signs up, php will make a folder with their username under the folder /user/

 

(and to add to my previous reply, ive also tried url such as: "http://localhost/user/USERNAME/40cabc290f43631cb4a7844790b1f2f8.png")

 

 

 

and thanks, that last code seems to have worked.... havnt got time to test it properly at the moment, my tea is ready xD

 

thanks for all the help cags

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.