重新路由参数的URL路径

时间:2013-01-23 04:13:49

标签: .htaccess

我想将网址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会有效。

谢谢!

1 个答案:

答案 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是可选的。

相关问题