News:

The "Support Requests" forum is now viewable by guests.

Main Menu

.httaccess help - Redirection (sorta)

Started by sixthcrusifix, December 30, 2005, 05:41:48 AM

Previous topic - Next topic

sixthcrusifix

My users are allowed to have custom pages to advertise their art etc. But for security reasons I am using MySQL instead of letting them write files.

I know you can do this with .httaccess but I forgot how

Can I make http://crystalchasm.net/username (the fake URL)

Into this: http://crystalchasm.net/MAIN/members/pages?username=username (the actual way to get to a userpage)

?
Visite me website at http://www.sixthcrusifix.com

webzone (archived)

It is an edited version of some code I suggested to you a while back.

Note : I recommend you to add something like /user/[username] to avoid conflicts with existing files. The code below does it.

RewriteEngine On
RewriteRule ^user/(.*)/?$ MAIN/members/pages.php?username=$1 [L]

neosquared

Just thought you might get some use out this 'cheat sheet' for mod_rewrite.
It's been invaluable to me.
http://www.ilovejackdaniels.com/apache/mod_rewrite-cheat-sheet
I never really understood how the expression syntax worked until I got this thing.
Don't take servers for granted.
Everything is flammable, if you get it hot enough.
Visit my website!  It'll make you cooler!

sixthcrusifix

#3
cool

Okay, I can't really get

RewriteEngine On
RewriteRule ^user/(.*)/?$ MAIN/members/pages.php?username=$1 [L]

to work....


It really needs to be like this:

They type: http://crystalchasm.net/pages/username

They are reffered to: They type: http://crystalchasm.net/pages/?user_name=username


I have tried using this:

RewriteEngine On
RewriteRule ^pages/(.*)/?$ pages/index.php?username=$1 [L]


but that just doesn't seem to actually do anything.
Visite me website at http://www.sixthcrusifix.com

GP™

sixthcrusifix,

The code would be:
RewriteRule ^pages/([A-Za-z0-9-]+/?$  pages/?user_name=$1 [L]

However, Mod Rewrite is not enabled if i'm correct, submit a request via the contact from for mod rewrite ;)

L8r,
Gordon

admin

mod_rewrite is enabled.  You do not need to use the Contact Form.

Please be sure your rule is correct.

Thank you,
FreePgs.com Admin

sixthcrusifix

#6
Quote from: gordon on January 05, 2006, 04:33:55 AM
sixthcrusifix,

The code would be:
RewriteRule ^pages/([A-Za-z0-9-]+/?$  pages/?user_name=$1 [L]

However, Mod Rewrite is not enabled if i'm correct, submit a request via the contact from for mod rewrite ;)

L8r,
Gordon

Well it works if I use this:


RewriteEngine On
RewriteRule ^pages/sixthcrusifix(.*)/?$ pages/index.php?user_name=sixthcrusifix [L]



But oonly for teh user named sixthcrusiifix, I wanted to make it to work for any username. If I can't do that can a write to the .httaccess file in PHP when a new user signs up to add them to the list???



When I use this:

RewriteEngine On
RewriteRule ^pages/(.*)/?$ pages/index.php?user_name=$1 [L]


O echoed the $user_name varibale to see what it was and using the above .htaccess made teh $user_name variable "index.php".


And using this:
RewriteEngine On
RewriteRule ^pages/(.*)/?$ pages/?user_name=$1 [L]


just makes the variable nothing.
______________________________________________________________________________________________________

EDIT: Using this:
RewriteEngine On
RewriteRule ^pages/user/(.*)/?$ pages/?user_name=$1 [L]


Allows me to use http://crystalchasm.net/pages/user/username[/b]

I DON'T know why either. I really don't wanna have to ad that extra "/user/" part but I think I may have to.
Visite me website at http://www.sixthcrusifix.com

admin

#7
You will need to specify another folder name to use for the direct URL (in the query)

You cannot have /pages on both sides of the equation.

You can set it to some other (non-existent) folder such as /page or /user

[If you want to use /pages, you will need to change the physical folder name (and second half of the equation) to something else such as page or user]

Your second test works because the rule no longer matches (/pages/user/* would not match /pages/*).  When the same is being used on both sides, it will be rewritten to a non-existent page.

[If you wish to use the same folder on both sides of the equation (i.e. the physical path and the URL) - you can use the following]

RewriteEngine On
RewriteCond %{QUERY_STRING} !user_name
RewriteRule ^pages/(.*)/?$ pages/?user_name=$1 [L]

This tells it to rewrite UNLESS the query string already contains "user_name".
(I have updated your .htaccess file to the above)
This means http://crystalchasm.net/pages/username will now work.

Thank you,
FreePgs.com Admin

admin

#8
More specifically, you can use:

RewriteEngine On
RewriteCond %{QUERY_STRING} !user_name
RewriteRule ^pages/([a-zA-Z0-9-_]+)/?$ pages/?user_name=$1 [L]

If you wish URLs to also work with the trailing slash
i.e. http://<domain>/pages/username and http://<domain>/pages/username/

(If your usernames contain other characters than a-z, A-Z, 0-9, - or _   You will need to modify the above entry.)
The above information has been saved into your .htaccess file.

Thank you,
FreePgs.com Admin

sixthcrusifix

Visite me website at http://www.sixthcrusifix.com