[英]htaccess subdomain rewrite to variable without being visible in the url
我需要使用htaccess将“子域”转换为变量。 但我不希望在重写后显示原始网址。
这是我到目前为止的内容:
rewritecond %{http_host} ^([A-Za-z0-9-]+)\.mysite.\com$ [nc]
rewriterule ^(.*)$ http://www.mysite.com/$1?aff=%1 [nc]
但这似乎不起作用。
我需要的是以下内容:
用户链接到: aff1.mysite.com
显示的URL更改为: www.mysite.com/
但是服务器读取的实际URL是: www.mysite.com/?aff=aff1
我还将添加各种语言,因此我可能甚至需要以下内容:
用户链接到: aff1.mysite.com
然后我从Cookie {HTTP_COOKIE} lang=([A-Za-z]+)$
如果Cookie中没有任何内容,则默认值应为“ en
”
然后,用户被重定向到aff1.en.mysite.com
然后应显示为: www.mysite.com/en/
但发送到服务器: www.mysite.com/?lang=en&aff=aff1
请告诉我这是可能的,以及我该如何实现。 我是新来的重写。 我已经查看了其他问题并尝试了他们的解决方案,但是不知何故无法使其完全适合我的需求。
另外... www.mysite.com
不应访问www.mysite.com/aff=www
它应该只是去/mysite.com/en/
因此,我在此上花费了比自己想要的时间更多的时间,但终于有了一些工作。 我没有在URL中传递变量,而是删除了一个cookie(无论如何,这最终还是我在页面上所做的,但这节省了一步-而且我不知道您可以通过重写来删除cookie) 。
如果有人用更少的代码行就能找到更好的解决方案,请随时发表评论或发布新答案。
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{http_host} ^www.example.info [nc] #if url starts with www.example.info
RewriteRule ^(.*)$ http://example.info/$1 [r,nc] #rewrite without the www
RewriteCond %{http_host} ^www.(.*).example.info [nc] #if url starts with www.(aff).example.info
RewriteRule ^(.*)$ http://%1.example.info/$1 [r,nc] #rewrite without the www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{http_host} ^(.*)\.example.info [nc] #if subdomain is aff
RewriteRule ^(.*)$ - [co=aff:%1:example.info:7200:/] #drop/update cookie with aff
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{http_host} ^(.*)\.example.info [nc] #if subdomain is aff
RewriteRule ^(.*)$ http://example.info/$1 [nc,R,L] #rewrite without subdomain
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.