I have a webcommunity, and it's growing now. I like to do a link makeover for my web, and then I need to know the best solution for my case.
Right now my htaccess looks kind of like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?page=user&username=$1 [L]
You are able to link to users like this domain.com/username and that's nice.
Then I have different pages like
- index.php?page=forum&id=1
- index.php?page=someotherpage&id=1&anotherid=5
- index.php?page=3rd
... and so on. I want them to look something like this:
- domain.com/forum/23/title-of-the-thread
- domain.com/page2/id1/id2
... and so on.
How do I make these pretty urls without removing my domain.com/username functionality? What solution would you suggest?
I was thinking about creating a file that checks the URL, if it matches any pages, and users and so on. Then it will redirect with a header location.
you actually have that file, it's index.php
that's wrong. HTTP redirect won't make your URLs look "pretty"
you have to include appropriate file, not redirect to.
Just change your rule to more general one
You basically have two options.
I've always worked with option 1, as this allows greatest flexibility with lowest mod_rewrite overhead. Option 2 may look something like:
you said
While "creating a file that checks the URL" sounds a lot like option 1, "redirect with a header location" is the worst you could do. That would result in
This can be done entirely with htaccess or php
read more about it here:
http://net.tutsplus.com/tutorials/other/using-htaccess-files-for-pretty-urls/ http://www.roscripts.com/Pretty_URLs_-_a_guide_to_URL_rewriting-168.html
If all of the urls you are going to rewrite are going to the same end point, you could simply use:
in index.php:
How you use the request uri is up to you, you could for example use a simple strpos check: