我想将网址http://example.com/index.php?path=controller/function
屏蔽为http://example.com/controller/function
。 <{1}}不需要出现。
如何使用htaccess文件执行此操作?
以下不起作用。
function
目前,如果我在浏览器中输入RewriteRule ^/?assets/(.*)$ assets/$1 [L] # directory for CSS, images, and JavaScript
RewriteRule ^$ /index [redirect]
RewriteRule ^([a-zA-Z]+)/?([a-zA-Z/]*)$ index.php?path=$1/$2 [L]
,则会收到404错误,但输入http://example.com/controller/function
会有效。
谢谢!
答案 0 :(得分:6)
你可以试试这个:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule ^([^/]+)(.*)?$ index.php?path=$1$2 [L]
内部映射
http://example.com/var1/var2
要:
http://example.com/index.php?path=var1/var2
保持传入的尾部斜杠行为,var2
是可选的。