我有一个index.php来处理所有的路由index.php?page = controller(简化)只是为了将逻辑与视图分开.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w\d~%.:_\-]+)$ index.php?page=$1 [NC]
Run Code Online (Sandbox Code Playgroud)
基本上: http://localhost/index.php?page = controller To
任何人都可以帮我添加重写
http:// localhost/controller/param/value/param/value(和soforth)
那将是:
HTTP://本地主机/控制器/ PARAM =值&PARAM =值
我不能让它与Rewriterule一起工作.
控制器可能如下所示:
<?php
if (isset($_GET['action'])) {
if ($_GET['action'] == 'delete') {
do_Delete_stuff_here();
}
}
?>
Run Code Online (Sandbox Code Playgroud)
并且:
<?php
if (isset($_GET['action']) && isset($_GET['x'])) {
if ($_GET['action'] == 'delete') {
do_Delete_stuff_here();
}
}
?>
Run Code Online (Sandbox Code Playgroud) 我希望我的网址如下所示
www.website.com/home&foo=bar&hello=world
我只想要改变第一个get参数
然而,实际的"幕后"网址是这样的
www.website.com/index.php?page=home&foo=bar&hello=world
我找到的所有教程都会更改所有参数.
任何帮助非常感谢!
这是我第一次尝试.htaccess
这就是我要的.
example.com/account/blitzen12 -> example.com/account/index.php?id=10&name=blitzen12
Run Code Online (Sandbox Code Playgroud)
我不想在重写中包含id,是否可能?
Note: id and name which is 10 and blitzen12 is retrive from the database.
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我尝试过的,但它没有用.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^account/(.*)$ ./account/index.php?page=account&id=$1&name=$2 [L,NC]
Run Code Online (Sandbox Code Playgroud)
HTML代码.
<a href="account/index.php?id=10&name=blitzen12">blitzen12</a>
Run Code Online (Sandbox Code Playgroud)
谁能帮我这个?谢谢.