Jump to content

forward-compatibility link (mod_rewrite)


web_master

Recommended Posts

So, with Apache, you can use a file named .htaccess. You put that file in your directory where your PHP resides and this will gives Apache instructions.

Apache is responsible for 'forwarding' your request to the PHP 'engine'. 

By default, all it will do is check the URL. If the filename ends with .php, it will try to tell PHP to execute that file.

But, with mod_rewrite (an Apache module), you can configure apache to change the URLs. For example, you can tell it to rewrite URLs with a certain pattern to another.

 

Here's a tutorial I found:

http://www.sitepoint.com/apache-mod_rewrite-examples/

 

Here's one I wrote myself (you can give me your comments if you read it):

http://www.mogosselin.com/friendly-url-for-php-with-apache/

 

If it doesn't work for you, you can query Google for 'php mod_rewrite tutorial' or 'php mod_rewrite example', etc. :)

I write in htaccess file next:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ /index.php?route=$1 [QSA]
</IfModule>

 

in PHP file is:

 

$route = explode("/", trim($_GET["route"], " \t\n\r\0\x0B/"));

 

so how can I split those variables, to make links in php files?

 

example

 

domain.com/content/main/header-of-text/155

 

content is the content file which is included into index.php

main is a some group of texts (name is stored in database - joined tables)

header-of-text is a header of the text stored in database - just writed

155 is the ID of text

 

without rewriting thats looks like domain.com?route=content&textgroup=7&id=155

 

...or am a totaly wrong... :(

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.