0

I'm curently building a website and I want to be able to rewrite urls like this

if I have foo.com/registration.php i want foo.com/registration.

Same if i have a member zone with foo.com/member.php i want something like foo.com/member/"membername"/ (the member name is stored in a session, or I can do a cookie).

I've already seen apache rewrite module, but i don't really understand it, or at least not enough to apply it to my website

Pedro del Sol
  • 2,774
  • 9
  • 40
  • 49
user3620691
  • 51
  • 1
  • 6
  • http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/ Begin your quest for rewriting URLS here. – Dorvalla May 09 '14 at 14:11
  • 1
    Note that `/registration` is the SEO-format URI produced by page links on your site, or typed in by a visitor. You will be using .htaccess to _rewrite_ it to `/registration.php` (see other answers for details), which is the form that your server and scripts can actually make use of. – Phil Perry May 09 '14 at 14:39

3 Answers3

0

You have to use Htaccess to convert your "http-friendly url" to your application.

For example: When your url will be: http://www.domain.com/this/link.html

Your htaccess will be:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*).html$ index.php?filepath=$1&%{QUERY_STRING} [L,QSA]

In your index.php you can get this filepath request by this:

$a_request_filepath = (empty($_GET['filepath'])) ? 'index' : $_GET['filepath'];

Your variable will have the value: this/link

For short explaination: You will look for the requested path. You remove .html from the filepath and send the rest of the path to index.php with a parameter of the path. So index.php?filepath=this/link is the same page

eL-Prova
  • 1,030
  • 10
  • 26
0

If you're using Apache 2.2.16 or later, mod_dir provides similar functionality than the Rewrite module in one line. It may be a little more performant since it doesn't invoke checks to see if the requested resource is a file or directory.

FallbackResource /index.php
Oscar M.
  • 1,068
  • 7
  • 9
0

Thanks for the help. If somebody is interrested, I learned the concept with a simple tutorial (no advertising, I just think he's good teacher ^^) : https://www.youtube.com/watch?v=OsCTzGASImQ&list=PLfdtiltiRHWGXVHXX09fxXDi-DqInchFD&index=1

user3620691
  • 51
  • 1
  • 6