.htaccess:重写 URI GET 参数?
.htaccess: Rewrite URI GET-Parameters?
我希望我的 URL 看起来像这样:
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=&action= [QSA,L]
RewriteEngine on
RewriteRule ^example-application_1.1/([^/]*)/([^/]*)/$ /example-application_1.1/?page=&action= [L]
这应该有效。
在index.php中可以得到变量:$_GET['page']
& $_GET['action']
.
我想你可以使用:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)" index.php?page=&action= [L]
我做到了:
RewriteEngine On
RewriteRule "^([^/]+)/([^/]+)/([^/]+)" index.php?page=&action=& [L]
RewriteRule "^([^/]+)/([^/]+)/" index.php?page=&action= [L]
所以如果用户输入:
https://example-prefix.example.com/pagename/actionname/id=123&category=456
URL会变成这样:
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=&action=& [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)/" index.php?page=&action= [L]
我希望我的 URL 看起来像这样:
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=&action= [QSA,L]
RewriteEngine on
RewriteRule ^example-application_1.1/([^/]*)/([^/]*)/$ /example-application_1.1/?page=&action= [L]
这应该有效。
在index.php中可以得到变量:$_GET['page']
& $_GET['action']
.
我想你可以使用:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)" index.php?page=&action= [L]
我做到了:
RewriteEngine On
RewriteRule "^([^/]+)/([^/]+)/([^/]+)" index.php?page=&action=& [L]
RewriteRule "^([^/]+)/([^/]+)/" index.php?page=&action= [L]
所以如果用户输入:
https://example-prefix.example.com/pagename/actionname/id=123&category=456
URL会变成这样:
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=&action=& [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)/" index.php?page=&action= [L]