/    Sign up×
Community /Pin to ProfileBookmark

Simulating a get variable as a directory

Okay so this may be less PHP and more Apache but the two are very interlinked so hopefully it wont be too much of a problem, just a heads up.

So i have been diving into .htaccess and having a look at the mouth-watering abilites it can provide. However, i was under the assumption that this (or somehting like it) was how websites today are able to seemily create new directorys for a post, a user or something like that.

To make sense of what the above means it is likely best i give an example.

Say a website used a get var in the url to show the user their personal userinfo such as domain/userarea?user=Fluffy.

I was under the impression that websites were now turning this into something like domain/userarea/Fluffy – much more clean and proffesional to say the least.

Is this not the case, are these websties making new files for every “X” thing?

i realise that .htaccess can be used to make domain/userarea/Fluffy be re-directed to domain/userarea?user=Fluffy but that is only so good.

Thanks for any help as always boys and girls … also to note that i’m asking more for a “yes or no” kinda answer and maybe some useful links if the answer is yes (don’t need pages of code and your time xD)

Regards

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@B_vidlerauthorDec 16.2014 — Hiya peeps- i will be starting this part of the website soon, so i could really use an answer. Just prodding it once t osee if this simply got forgotten about in the pile of posts xD
Copy linkTweet thisAlerts:
@NogDogDec 16.2014 — This appears to give a decent description of how to do it: http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/

Basically, you'll pass the URL string to your main PHP file (e.g. index.php), which will then break it down into its pieces, and then provide them as arguments to the applicable (controller) function.

Or you could just build your application on top of an existing framework that already does most of this for you (you then typically just need to define the applicable routes so that it knows what function to call with which parameters).
Copy linkTweet thisAlerts:
@SimonvetterliDec 16.2014 — I did like this and it works fine for me:

In the url I will have like http://www.liveandletdive.fi/en/divesites/ .

"Internal" I have a file called divesites.php and for the language I use en, ge, fi and nl. So to call the each language I use internal the follow url: divesites.php?lang=en for english. And so on for the other languages.

Is this what You mentioned?

[CODE]# 1 YEAR
<FilesMatch ".(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>

# 1 WEEK
<FilesMatch ".(txt|xml|js|css)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

# NEVER CACHE - notice the extra directives
<FilesMatch ".(html|htm|php|cgi|pl)$">
Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
</FilesMatch>

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^62.73.58.149
RewriteRule (.*) http://www.liveandletdive.fi/$1 [R=301,L]

## Adding a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} s/+(.*?)[^/][?s]
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([a-z]{2})/?$ index.php?lang=$1 [L,QSA,NC]
RewriteRule ^([a-z]{2})/([a-z]+)/?$ $2.php?lang=$1 [L,QSA,NC]
[/CODE]
Copy linkTweet thisAlerts:
@B_vidlerauthorDec 19.2014 — Hi Guys! - that was exactly what i meant and was looking for. Thanks!

Ironically, the PHP book i bought alone at the same timeas writing this post gets onto this topic atarund page 100 which, until hitting the chapter, i did not know. Anyway, the two resources combine are making this pretty easy now ?.
×

Success!

Help @B_vidler spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.11,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...