MEM*_*MEM 2 .htaccess mod-rewrite
我现在有以下.htaccess.
<IfModule mod_suphp.c>
suPHP_ConfigPath /home/abc/php.ini
</IfModule>
RewriteEngine on
RewriteCond $1 !^(index\.php|media|css|js|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
AuthType Basic
AuthName "Está dominado!!"
AuthUserFile "/home/abc/.htpasswds/public_html/passwd"
require valid-user
Run Code Online (Sandbox Code Playgroud)
现在问题是,我想,如果在/删除该查询字符串后找到任何查询字符串.
所以:如果我们有:
http://www.abc.com/?somethinghere234
它应该重定向到:
http://www.abc.com/
如果我们有:
htpp ://www.abc.com/something/?id212
重定向到:
HTPP://www.abc.com/something/
更新:我试过这个:
尝试A)
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule .* /index.php/ [L,QSA]
Run Code Online (Sandbox Code Playgroud)
跳跃^(.*)$将允许查询字符串上的任何内容......
我也试过这个:
尝试B)
RewriteEngine on RewriteCond $ 1!^(index.php | media | css | js | images | robots.txt)RewriteCond%{QUERY_STRING} ^(.)$ RewriteRule ^(.)$ http://abc.com/ [L]
这将返回500内部服务器错误.
尝试C)
RewriteEngine on
RewriteCond $1 !^(index\.php|media|css|js|images|robots\.txt)
#RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ http://abc.com/ [R=302,L]
Run Code Online (Sandbox Code Playgroud)
我承认我有点迷失在这个.htaccess sintax上.
尝试D)
RewriteEngine on
RewriteCond $1 !^(index\.php|media|css|js|images|robots\.txt)
RewriteCond %{REQUEST_URI} !^/
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)$ http://abc.com/ [R=302,L]
Run Code Online (Sandbox Code Playgroud)
请建议,MEM
以下应该有效:
RewriteCond %{QUERY_STRING} .
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^ /index.php/? [L]
Run Code Online (Sandbox Code Playgroud)
从Apache文档:
如果要删除现有查询字符串,请仅使用问号结束替换字符串
编辑(再次):作为外部重定向(如果您的应用程序中根本没有任何查询字符串,您可能甚至不需要第二个RewriteCond):
这将告诉客户端在没有查询字符串的情况下请求相同的URI.
RewriteEngine on
# redirect to same URI, but without query string
RewriteCond %{QUERY_STRING} .
RewriteRule ^ %{REQUEST_URI}? [R=301]
# CodeIgniter "magic"
RewriteCond $1 !^(index\.php|media|css|js|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16160 次 |
最近记录: |