skip to Main Content

as the title says im a rookie in the ‘URL Rewriting’ field and i’d like to ask a question that could help many others like me.

Let’s say we have an url like this:

http://myepicsite.wow/index.php?value_x=1&value_y=2&value_z=3

How can one rewrite this url to something like this(seofriendly) without writing a line of code for every page that is generated from those _GET[] variables? :

http://myepicsite.wow/index.php/1/2/3

2

Answers


  1. Try adding this to your .htaccess

     RewriteEngine On
     RewriteCond %{HTTP_HOST} ^myepicsite.wow [NC]
     RewriteRule ^(.*)$ http://myepicsite.wow/$1 [L,R=301]
     RewriteRule ^index.php/(.+)/(.+)/(.+)/?$  index.php?value_x=$1&value_y=$2&value_z=$3&%{QUERY_STRING} [L]
    
    Login or Signup to reply.
  2. Try:

    RewriteEngine On
    RewriteRule ^index.php/([^/]+)/([^/]+)/([^/]+)$ /index.php?value_x=$1&value_y=$2&value_z=$3 [L,QSA]
    

    Then you just need to make sure your links all look like http://myepicsite.wow/index.php/1/2/3.

    However, you can already read these from index.php even without a rewrite rule. In your index.php script, you should be able to read the $_SERVER['PATH_INFO'] variable and see /1/2/3, then just explode that into an array and assign them to the value_x/y/z variables.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search