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
https://forums.phpfreaks.com/topic/46850-friendly-urls-and-htaccess/
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.
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.