Apache 重写规范的规则定制
这是我现在在htaccess文件中使用的代码Apache 重写规范的规则定制,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,这是我现在在htaccess文件中使用的代码 <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|webp|html)(\.gz)?(\?.*)?$"> <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule .* - [E=CANONICAL:http://%{HTTP_HOST}%{REQUEST_U
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|webp|html)(\.gz)?(\?.*)?$">
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* - [E=CANONICAL:http://%{HTTP_HOST}%{REQUEST_URI},NE]
RewriteCond %{HTTPS} =on
RewriteRule .* - [E=CANONICAL:https://%{HTTP_HOST}%{REQUEST_URI},NE]
</IfModule>
<IfModule mod_headers.c>
Header set Link "<%{CANONICAL}e>; rel=\"canonical\""
</IfModule>
</FilesMatch>
重新启动发动机
重写cond%{HTTPS}=在…上
重写规则。*-[E=CANONICAL:http://%{http_HOST}%{REQUEST_URI},NE]
RewriteCond%{HTTPS}=on
重写规则。*-[E=CANONICAL:https://%{HTTP_HOST}%{REQUEST_URI},NE]
标题集链接“rel=\“canonical”
我想做的是让这里的规范与HTTP_主机不同
让我们假设HTTP_主机现在是example.com/es/,但我需要这个规范是example.com/en/
我如何使用修改后的上述代码重写canonical的URL以反映example.com/en/请尝试以下操作:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS}s ^on(s)|off
RewriteCond http%1://%{HTTP_HOST}%{REQUEST_URI} ^(.*?)/es/(.*)$ [NC]
RewriteRule .* - [E=CANONICAL:%1/en/%2,NE,S=1]
RewriteCond %{HTTPS}s ^on(s)|off
RewriteRule .* - [E=CANONICAL:http%1://%{HTTP_HOST}%{REQUEST_URI},NE]
</IfModule>
重新启动发动机
重写cond%{HTTPS}s^on(s)| off
重写条件http%1://%{http_HOST}%{REQUEST_URI}^(.*)/es/(.*)$[NC]
重写规则。*-[E=规范:%1/en/%2,NE,S=1]
重写cond%{HTTPS}s^on(s)| off
重写规则。*-[E=CANONICAL:http%1://%{http\u HOST}%{REQUEST\u URI},NE]
你修好了,伙计!非常感谢你的帮助。