0

I am looking for your recommandations on what would be the best way to implement friendly URLs.

What I currently do is redirect all 404 requests to folders or files that do not exist to index.php. index.php reads the query string and makes a database call to see if the url is in the page_urls table then based on the page type fetches content etc etc.

The .htaccess contains the following lines:

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php [L]

Is there a more "clever" way of doing this please? Thank you.

Thank you.

3
  • That's too broad a question. You really should describe more of what you mean by "clever". Commented Nov 23, 2010 at 22:39
  • One thought on this that isn't about the mechanics of the URL rewriting: Think about what HTTP status codes you're sending back. If you find a page in the DB that you think is what was desired, a permanent redirect (301) to that page's canonical URL is probably best. Or, if you want to send the message that the resources at the failing URLs are truly gone, return a 404 (optionally including page content that think might be helpful to a lost human). If you're returning a normal (200, "OK") response, you're sort of saying that it's OK to keep using those (broken) URLs. Commented Nov 24, 2010 at 1:59
  • Hey. casablanca: "clever" is anything that can be done better. The above variant works, so I am looking for something better if exists. pbx: I am using header() to set a 200 OK or 404 not found for good URLs or bad URLs respectively. Commented Nov 26, 2010 at 20:17

1 Answer 1

1

The best way I've found is to do something like the following:

RewriteEngine on RewriteRule ([a-zA-Z0-9_-]*)\.html index.php?page=$1 [L] 
Sign up to request clarification or add additional context in comments.

1 Comment

It's an idea, thanks. But it's basically the same system only with a different way of redirecting.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.