PHP都开始使用mod_rewrite的参数参数、PHP、mod_rewrite

2023-09-02 00:42:36 作者:〇o。隱灬~

我设计我的应用程序。我应该让接下来的事情就。全部搞定参数(?VAR =值)mod_rewrite的帮助应该变换到/ var /值。我怎样才能做到这一点?我只有1 PHP文件(的index.php),因为我usign了的FrontController模式。你能帮助我这个mod_rewrite规则?_爱对不起,我的英语水平。谢谢你在前进。

I am designing my application. And I should make the next things. All GET parameters (?var=value) with help of mod_rewrite should be transform to the /var/value. How can I do this? I have only 1 .php file (index.php), because I am usign the FrontController pattern. Can you help me with this mod_rewrite rules?Sorry for my english. Thank you in advance.

推荐答案

我做这样的事情上使用搜索引擎友好的URL地址的网站。

I do something like this on sites that use 'seo-friendly' URLs.

在.htaccess:

In .htaccess:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [L]

然后在index.php文件:

Then on index.php:

if ($_SERVER['REQUEST_URI']=="/home") {
    include ("home.php");
}

本的.htaccess规则告诉它加载的index.php,如果该文件或目录的要求没有被发现。然后你只需解析请求的URI来决定的index.php应该做的。

The .htaccess rule tells it to load index.php if the file or directory asked for was not found. Then you just parse the request URI to decide what index.php should do.