-1

I've seen websites have profile pages do things like 'http://www.example.com/myusername/ show the the person with the username 'myusername's' profile. I was wondering how to do this?

I've seen examples on how to do this with htaccess but it does a full redirect, not allowing post data, get data, etc. How could I do this?

user3894475
  • 149
  • 2
  • 8
  • `.htaccess` is a great place to start. Please show the contents of your `.htaccess` file and describe specifically what you want to happen and what goes wrong. – showdev Dec 03 '14 at 01:03
  • Like I said, I have no experience doing this and I've only seen examples of using pre-made folders, like making /resume/ go to resume.pdf, etc. – user3894475 Dec 03 '14 at 01:05

2 Answers2

2

Use .htaccess's mod_rewrite option to create rewrites that will maintain the query string and/or posted data. A quick example (taken from CodeIgniter) :

RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

This will mean that all requests go to index.php and your index.php script would be setup to parse this URL into a proper class and/or function. This allows for a single entry point that can be managed by a system. This is used by all major systems, from Wordpress to Magento to Laravel 4 to CodeIgniter.

Mikel Bitson
  • 3,583
  • 1
  • 18
  • 23
  • 500 Internal Server Error I copied that exactly how you posted it and I got that. Could it be that I don't have a robots.txt? – user3894475 Dec 03 '14 at 01:23
  • Mod_rewrite is an Apache module that needs to be configured on the server. As to not duplicate content, check out: http://stackoverflow.com/a/3131259/3525315 – Mikel Bitson Dec 03 '14 at 01:26
0

.htaccess allows to "post" (the right word would be GET) data in a querystring using a directory-like style You have to activate the RewriteEngine and then write a rule to convert the querystring expected by your page in a directory-style sintax, in order to write these rules you have to use some regular expression to map the elements in the url that will be recognised as the variables and the respective values of you querystring

For example if you want to rewrite a query string like this:

www.sitename.com/showimages.php?album=sea&photo=mysurf    

in a query like this:

www.sitename.com/sea/mysurf

you have to write the sequent rule:

 RewriteEngine on
 RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/?$ /showimages.php?album=$1&photo=$2 [NC,L]     

here is an interesting and simple guide to ".htaccess URL rewrite" http://edward-designer.com/web/htaccess-url-rewrite-simplified/

I apologize for my bad English

Hope this helps