I want to create a web site with pure PHP. I want to hide the url parameters. I.e. I want to make my web site with clean urls. Is there is any way to do this with out using any framework? Is cURL helpful to do this?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Nope, no curl or framework doing this. Nor php at all.
It is web server who deal with urls.
So, if you want fake urls, you have to set up your web server to redirect certain urls to certain scripts.
The most common way is to use Apache web server with mod_rewrite module
Try to rewrite url using php and rewrite url using .HTACCESS.
For example, original url,
with php
and with .HTACCESS file
Just have a look on it...before you start your stuffs
From what I have read and understand of it, there's 2 ways you can do this:
mod_rerite
where everything seems to re fone through rewrite rules through the.htaccess
file fairly simple to do but can put big load on webserver with large sites.htaccess
but only to redirect everything back to the index.php where a dispatcher reroutes paths as necessary. There's a fantastic tutorial of this at phpvideotutorials.com the tutorial is called the tumblelog.First of all: It is not possible with PHP only (at least not the forms of URL I think of when reading clean URL). The web server needs to know how to handle requests and what requests are meant to be passed to your PHP script. Otherwise you will probably just get a 404 response.
Because the default behavior of a web server is to just take the requested URL path and try to map it to an existing file below the document root. If a corresponding file was found, either the file’s content is passed back to the client or – as in case of PHP files – the file’s content is passed to an appropriate interpreter and the returned data is passed back to the client. And if the file was not found, well, it responds with the status code 404. So at some point you need to configure your web server.
But after that, when the request was passed to your PHP script, you sure can use just PHP to establish clean URLs. And I would rather suggest to do that with PHP than with web server utilities. Because your PHP application should know best how to handle a requested URL.
In PHP, all required information are in the
$_SERVER
variable:$_SERVER['REQUEST_URI']
holds the requested URL path and query (you can parse that withparse_url
), and$_SERVER['PATH_INFO']
holds the PATH_INFO if you’re using that (see Apache’sAcceptPathInfo
directive).See URL rewriting in PHP without
.htaccess
if you don't want to or can't use.htaccess
, else refer to How to: URL rewriting in PHP?.