Reputation: 179
Hi guys I've been working with $_GET['whatever']
now this time I need something that I've never had done before I've seen this url domain.com/author/name_of_user
and my question is how do I get data in that kind of URL? I've been looking for answers and all they say is $_GET['']
;
so example I have this link http://localhost/domain/attachments.php
how do I change this one to http://localhost/domain/attachments/
in the first place? and how will I be able to get data from that is it from $_GET['']
? please help me I'm really confused
Upvotes: 1
Views: 339
Reputation: 120
You will need .htaccess file at the root of your website that will rewrite your website URLs from example.com/index.php?var1=12&var2=23 to something similar to example.com/pagename/12/23 Here are some basics of using .htaccess for URL rewriting: http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html
Upvotes: 2
Reputation: 4834
That is called URL rewrite:
http://httpd.apache.org/docs/2.2/rewrite/
http://www.iis.net/downloads/microsoft/url-rewrite
Those are links to url rewritting in Apache / IIS.
In short, it takes: http://localhost/domain/attachments.php
and "transform" (or rewrite) it to
http://localhost/domain/attachments
(or whatever you prefer).
Normally it is used to improve SEO.
You can still use $_GET normally because it's just a transformation, in the end you still have whatever.php?var=value&.... only that it shows differently for the browser.
Upvotes: 5
Reputation: 1370
It is pretts simple to rewrite a URL. Apache comes with a mod called mod_rewrite
that handles this. The only thing you need to do is write some rules in your .htaccess
.
I recommend you to read this article: htaccess Tricks
Upvotes: 3
Reputation: 21282
You should use the Apache's rewrite module in order to rewrite your URLs.
In your specific case - after you have activated the mod_rewrite
- try this rewrite rule:
RewriteEngine On
RewriteRule ^domain/attachments/?$ /domain/attachments.php
However this doesn't affect your $_GET
array in any way.
Upvotes: 2