简体   繁体   中英

Which alternatives do I have for developing a website navigation without .htaccess?

Just in theory: Almost all modern websites work this way:

somedomain.com/layer1/layer2/action

For example:

http://stackoverflow.com/questions/ask

Typically this is done with .htaccess and ModRewrite Engine. A while ago I stumbled over an article that described something which came right out of php. I don't remember the name anymore. That piece of PHP code was aware of the currently opened URL. It was able to tell what domain is called, what TLD is called, what's the first directory, what's the second directory, what's the called file, etc.

I know the Kohana Framework uses this technology, but don't know where to look at. Anyone familiar with this?

What you mean is making use of the PATH_INFO environment variable. See eg here

Without access to .htaccess settings, you will however always have one filename.php in the path with this method:

www.domain.com/filename.php/questions/ask/

What is happening beneath the surface of .htaccess in most cases is what you're looking for. Many cases the .htaccess file simply delegates the task to an index.php file, which itself is prepared to handle the values passed in representing a controller, a method, and parameters.

I don't see why you couldn't simply create your own .php file to parse out the url and handle the values from there. You'll merely have to use that .php file as your base in all urls though:

www.mysite.com/index.php/controller/method/parameter1/parameter2

您可以使用apache的错误文档,但它只是一个黑客(也作为重写)而不是一个干净的解决方案。

You could use a combination of HTTP headers, but those can be unreliable on some web servers. To see what HTTP headers are available on your server, make a page with just this:

<?php phpinfo(); ?>

Look for the PHP Variables section, specifically these are the ones that you can potentially use:

_SERVER["HTTP_HOST"]
_SERVER["SCRIPT_NAME"]

Have a look at the Front controller pattern .

Essentially you get all your requests to be redirected to a single PHP file that decodes the URL and decides on the next action.

This isn't PHP-specific btw.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM