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
https://forums.phpfreaks.com/topic/196623-is-this-code-correct/
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

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

 

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

Archived

This topic is now archived and is closed to further replies.

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