Ale*_*tau 4 php apache url .htaccess mod-rewrite
我正在设计我的应用程序.我应该做下一件事.在mod_rewrite的帮助下,所有GET参数(?var = value)都应转换为/ var/value.我怎样才能做到这一点?我只有1个.php文件(index.php),因为我使用了FrontController模式.你能帮我解决这个mod_rewrite规则吗?
对不起我的英语不好.先感谢您.
我在使用"seo友好"网址的网站上做了类似的事情.
在.htaccess中:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [L]
Run Code Online (Sandbox Code Playgroud)
然后在index.php上:
if ($_SERVER['REQUEST_URI']=="/home") {
include ("home.php");
}
Run Code Online (Sandbox Code Playgroud)
.htaccess规则告诉它如果找不到要求的文件或目录,则加载index.php.然后你只需解析请求URI来决定index.php应该做什么.
.htaccess中的以下代码将重写您的URL,例如:/api?other=parameters&added=true至/?api=true&other=parameters&added=true
RewriteRule ^api/ /index.php?api=true&%{QUERY_STRING} [L]
Run Code Online (Sandbox Code Playgroud)