.htaccess 将URL路径重新路由到参数
我想屏蔽URL.htaccess 将URL路径重新路由到参数,.htaccess,.htaccess,我想屏蔽URLhttp://example.com/index.php?path=controller/function至http://example.com/controller/function功能不需要存在 如何使用htaccess文件执行此操作 以下内容不起作用 RewriteRule ^/?assets/(.*)$ assets/$1 [L] # directory for CSS, images, and JavaScript RewriteRule ^$ /index [redir
http://example.com/index.php?path=controller/function
至http://example.com/controller/function
<代码>功能不需要存在
如何使用htaccess文件执行此操作
以下内容不起作用
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]
当前,如果我输入http://example.com/controller/function
在浏览器中,我收到404错误,但输入http://example.com/index.php?path=controller/function
有效
谢谢 您可以尝试以下方法:
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
是可选的。您可以尝试以下操作:
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
是可选的。如果需要重写http://example.com/uploads/var1/var2/file.txt
至http://example.com/index.php?filepath=var1/var2/file.txt
?如果需要重写http://example.com/uploads/var1/var2/file.txt
到http://example.com/index.php?filepath=var1/var2/file.txt
?