Jump to content

Friendly urls and .htaccess


dhimok

Recommended Posts

Hello everyone.

 

Do you know a good advanced guide about mod_rewrite and friendly urls?

 

I am using the code below in my .htaccess file. It works very well as long as I use one querystring. Sometimes I need to pass many values thru querystrings and the page gets vulnerable. Any one knows a good way doing this

 

the urls I get are like:

1.html

2.html

..

5.html

etc.

 


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)\.html$ index.php?c=$1[L]

 

I dont know if I was clear enough but Thanks anyway :)

Link to comment
Share on other sites

well friendly urls are clear of ? = and & (and if you are strict - any non-alphanumeric bar '/')

 

so what you want to achieve is something like

 

http://www.yoursite.com/books/foreign

 

that way you can use

Options +FollowSymLinks
RewriteEngine on
RewriteRule !\.(gif|jpg|png|css)$ index.php [NC, L]

 

then in your index.php

 

$url = strip_tags($REQUEST_URI);
$url_array = explode("/",$url);
array_shift($url_array);

 

$url[0] will be 'books' and $url[1] will be 'foreign'.

 

use the resulting values of the array to control the flow of your scripts.

 

so you can use something like

 


switch($url[0])
{
case 'films':
  // do film stuff.
  break;
case 'plays':
  // do play stuff.
  break;
case 'books':
  // do book stuff.
  break;
default:
  // show home page.
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.