Jump to content

[SOLVED] url rewriting


Ninjakreborn

Recommended Posts

What options are available to write url's.

After finally looking up mod_rewrite, it's not something you can do with PHP.  It is something done in apache, something like codeignitor does it on all systems, and I am unaware of how they do it, I can't find anything about it. I also know htaccess is another option, but not all server's support or allow htaccess file's so that is another thing that won't work.  Is there a way using just php to rewrite all incoming url's and make them segment based?

Link to comment
https://forums.phpfreaks.com/topic/38185-solved-url-rewriting/
Share on other sites

As far as I know, only web servers can rewrite URLs. You cannot have the end product (a PHP page) rewrite the path to itself. You could probably write your own web server in PHP, thus using PHP to rewrite the URLs, but that would just be silly.

 

Did you go through the docs?

Link to comment
https://forums.phpfreaks.com/topic/38185-solved-url-rewriting/#findComment-182797
Share on other sites

if it's the CI/Cake/Wikipedia, etc, etc way you like then it's very simple. all you need is an apache server and a htaccess file. My framework uses similar to this in its .htaccess which is located in my web root:

 

RewriteEngine on
RewriteCond $1 !^(favicon\.ico|index\.php|js|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

 

which basically says: if it's not my favicon.ico, index.php, js folder, css folder or my robots.txt file, then throw it through my web root's index.php. i then pick up the segments using $_SERVER['PATH_INFO'] which gives me a single string containing everything after the domain name. without mod_rewrite, you can get a similar effect using a url like:

 

 

using mod_rewrite for this example has two benefits here though:

1, removes the need to have index.php in the URL

2, restricts access to ANY file/dir you dont specify in your .htaccess file automatically.

 

there are lots of ways of structuring the URI though. take a look at the URI of this forum page:

 

index.php/topic,126674.0.html

 

if you ran that on your own server, then a line in your index.php such as: echo $_SERVER['PATH_INFO'] would output: /topic,126674.0.html

Link to comment
https://forums.phpfreaks.com/topic/38185-solved-url-rewriting/#findComment-182806
Share on other sites

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.