0

I want to change my url :

items.php?category=all&page=2

Into :

items/all/2

I understand that I am able to do this using mod_rewrite. What i want to know is after using mod_rewrite, am i able to use

<a href="items/all/2">

or do i still have to use

<a href="items.php?category=all&page=2">

I want to be able to use the first one. If it can't be done using mod_rewrite, what other ways can I achieve this result?

QiZhi
  • 15
  • 5

2 Answers2

0

You can use mod_rewrite for this and after that you can use string like this <a href="items/all/2"> in your code, try using below rule.

Note that it is rewriting not redirecting so your link above will processed as <a href="items.php?category=all&page=2"> inside apache.

Put below rule in .htaccess file inside your root directory.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([\w]+)\([\w]+)\([\w]+)$ $1.php?category=$2&page=$3 [QSA,L]

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

Abhishek Gurjar
  • 7,152
  • 9
  • 35
  • 40
0

Indeed to get nicer looking URLs, you can use mod_rewrite. Using this kind of rule in your .HTACCESS file:

RewriteRule ^voitures/([a-zA-Z0-9_-]+)$ /vehicules.php?gamme=$1 [L]

Allows you to access example.com/vehicules.php?gamme=xyz via example.com/voitures/xyz

SevenEleven
  • 1,860
  • 2
  • 29
  • 28
massaoud
  • 1
  • 1