Mat*_*att 3 mod-rewrite rewrite httpd.conf apache-2.2
我正在将查询字符串重写为漂亮的 URI,例如:index.php?q=/en/contact
变成/en/contact
并且一切正常..
# httpd.conf
# HANDLE THE QUERY
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)
甚至可以重写单个查询来强制https
和强制其他所有内容http
吗?我尝试了许多不同的方法,这些方法通常以无限循环结束。我可以编写一个插件来在 PHP 中执行此操作,但认为在服务器 conf 中处理此问题会更有效。我很乐意提供任何建议。
编辑:
为了澄清,我希望能够将非 SSL 重写为http://example.com/index.php?q=/en/contact
启用的 SSLhttps://example.com/en/contact
以及每个未/en/contact
写入的查询http://example.com/...
htaccess 示例:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^en/contact$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTPS} =on
RewriteRule !^en/contact$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)
http://domain/en/contact
重定向以https://domain/en/contact
重写 index.php?q=en/contact
http://domain/en/fo
重写为 index.php?q=en/fo
https://domain/en/fo
重定向以http://domain/en/fo
重写 index.php?q=en/fo
https://domain/en/contact
重写为 index.php?q=en/contact