我希望我的网址如下所示:
https://example-test.example.com/example-application_1.1/index.php?page=pagename&action=actionname
但是用户只应输入:
https://example-test.example.com/example-application_1.1/pagename/actionname/
是否可以在.htaccess中使用RewriteRule运行?我无法弄明白。
我的.htaccess文件目前看起来像这样:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^example-test\.example\.com
RewriteRule ^example-application_1\.1/([^/]+)/([^/]+)/?$ /example-application_1\.1/index.php?page=$1&action=$2 [QSA,L]
答案 0 :(得分:1)
我做到了:
RewriteEngine On
RewriteRule "^([^/]+)/([^/]+)/([^/]+)" index.php?page=$1&action=$2&$3 [L]
RewriteRule "^([^/]+)/([^/]+)/" index.php?page=$1&action=$2 [L]
因此,如果用户输入:
https://example-prefix.example.com/pagename/actionname/id=123&category=456
网址将变为:
https://example-prefix.example.com/index.php?page=pagename&action=actionname&id=123&category=456
如果您仍想访问文件,请执行以下操作:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)/([^/]+)" index.php?page=$1&action=$2&$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)/" index.php?page=$1&action=$2 [L]
答案 1 :(得分:0)
RewriteEngine on
RewriteRule ^example-application_1.1/([^/]*)/([^/]*)/$ /example-application_1.1/?page=$1&action=$2 [L]
这应该有用。
在index.php中,您可以获得变量:$_GET['page']
& $_GET['action']
。
答案 2 :(得分:0)
我认为你可以使用:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)" index.php?page=$1&action=$2 [L]