如何对搜索引擎友好的URL与子域使用htaccess的? [英] How use htaccess for seo friendly url with subdomains?

查看:115
本文介绍了如何对搜索引擎友好的URL与子域使用htaccess的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的htacess文件:

This is my htacess file:

RewriteEngine on    
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com(.*)
RewriteRule .* inside.php?tx=%1&filter=%2 

此网址:hello.mydomain.com去www.mydomain.com/inside.php?tx=hello~~V 那是正确的。

This url: hello.mydomain.com goes to www.mydomain.com/inside.php?tx=hello Thats correct.

现在我需要这个网址hello.mydomain.com/bye/去www.mydomain.com/inside.php?tx=hello&filter=bye~~V,但不起作用。只到www.mydomain.com/inside.php?tx=hello~~V

Now i need this url hello.mydomain.com/bye/ goes to www.mydomain.com/inside.php?tx=hello&filter=bye, but don't work. Only goes to www.mydomain.com/inside.php?tx=hello

这htaccess的是忽略了第二个变量(再见)。请帮助。

This htaccess is ignoring the second variable (bye). Help please.

推荐答案

%{HTTP_HOST} 仅包含主机名( hello.mydomain。 COM ),那么你的第二个反向引用不具有任何东西。改变你的重写规则以下是应该给你期望的行为:

%{HTTP_HOST} only contains the host name (hello.mydomain.com), so your second backreference doesn't have anything in it. Changing your RewriteRule to the following should give the behaviour you're expecting:

RewriteRule ^([^/]*) inside.php?tx=%1&filter=$1 

编辑:要更正您的评论描述的情况,整个规则集应该如下:

To correct the situation described in your comment, the entire ruleset should be as follows:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com(.*)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*) inside.php?tx=%1&filter=$1

这篇关于如何对搜索引擎友好的URL与子域使用htaccess的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆