Jump to content
New Reality: Ads For Members ×

Variables as directories


Porl123

Recommended Posts

I'm not really sure if this has anything to do with PHP itself, but I'm not at all sure how you'd do this. I often see profile pages on websites where the link to access them is in this format:

 

http://www.website.com/profiles/user

 

As apposed to:

 

http://www.website.com/profiles.php?username=user

 

I can see how you'd create the first method using GET variables, but how would the first work? Thanks

Link to comment
https://forums.phpfreaks.com/topic/224511-variables-as-directories/
Share on other sites

Yes, you have to add it to your .htaccess.  I'm not very good with mod_rewrite rules but if you search this forum you will see examples similar to yours, it's a pretty common question.  This may help:

http://www.phpfreaks.com/forums/mod_rewrite/passing-additional-get-variables/

What errors are you getting with .htaccess ?

 

When i was attempting to make something, i made use of wordpress' htaccess below, and then everything is grab-able with REQUEST_URI.

 

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Options +FollowSymLinks +Indexes

RewriteEngine on

RewriteBase /

RewriteRule ^profiles/([^.]+)$ profiles.php?username=$1 [L]

 

with the links pointing to

 

domain.com/profiles/username

 

if you're only getting there by a link, it shouldn't cause any problems. Now forums, they are harder set-up so they go to a URL like that.

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.