我有以下 .htaccess 规则。我需要在这个块中添加一些规则。我不想失去我的旧人。
<FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
Order allow,Deny
Deny from all
</FilesMatch>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
我的规则是这样的:
- if HTTP_USER_AGENT includes BotOne
- or HTTP_USER_AGENT includes OtherBot
- or HTTP_COOKIE user_id != 1
- if REQUEST_URI is "/" main directory
- or REQUEST_FILENAME includes "utm_source"
- or REQUEST_FILENAME includes "utm_medium"
- or REQUEST_FILENAME includes "utm_campaign" and "utm_content"
- if REQUEST_FILENAME doesn't include "/blog/"
- or REQUEST_FILENAME doesn't include "gif"
- or REQUEST_FILENAME doesn't include "jpg"
- then RewriteRule all files to index.html
我试过这个。但没有帮助。我该如何编写这些规则?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteCond %{HTTP_USER_AGENT} "BotOne|OtherBot" [NC,OR]
RewriteCond %{HTTP_COOKIE} !^.*user_id=1 [NC]
#
RewriteCond %{REQUEST_URI} \/ [NC,OR]
RewriteCond %{REQUEST_FILENAME} ^utm_source.* [NC,OR]
RewriteCond %{REQUEST_FILENAME} ^utm_medium.* [NC,OR]
RewriteCond %{REQUEST_FILENAME} ^utm_campaign.* [NC,OR]
RewriteCond %{REQUEST_FILENAME} ^utm_content.* [NC]
#
RewriteCond %{REQUEST_FILENAME} !\/blog\/.* [NC,OR]
RewriteCond %{REQUEST_FILENAME} !gif.* [NC,OR]
RewriteCond %{REQUEST_FILENAME} !jpg.* [NC]
RewriteRule ^.*? index.html [R=301,L]
</IfModule>
我要重定向的主要 URL 如下所示:
* http://example.com => http://example.com/index.html
* http://example.com/ => http://example。 com/index.html
* http://example.com/?utm_source=michael => http://example.com/index.html
* http://example.com/?utm_medium=twitter => http:// example.com/index.html
* http://example.com/?utm_campaign=camp2&utm_content=somewhere => http://example.com/index.html
* http://example.com/blog/ * => 否重定向
* http://example.com/myfile.jpg=> 无重定向
* http://example.com/myfile.gif => 无重定向
如果(用户代理是“BotOne”)或(用户代理是“OtherBot”)或(他/她的 Cookie 用户 ID 不是 1),将触发此重定向。
任何查询参数都将被删除。