htaccess的和重写 [英] htaccess and rewriting

查看:181
本文介绍了htaccess的和重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是提出我的webside一个子域主要becouse我希望有一个spesific地址吧。

I just made a subdomain on my webside mainly becouse i want a spesific address to it.

比方说我的网站是: http://website.com 而我的子域名是 http://sub.website.com 的主文件夹中的/ home /用户名/的public_html /子/

Lets say my website is : http://website.com And my subdomain is http://sub.website.com with its main folder in /home/username/public_html/sub/

当我进入子域的地址的地址suddently更改为 HTTP // website.com /子/

When i enter the subdomain address the address suddently changes to http//website.com/sub/

如何能保持子域的地址?

how can i keep the subdomain address?

编辑丹尼斯:

我有一个指导规则均 http://www.website.com http://website.com

i have a rule that directs all http://www.website.com to http://website.com

我用

RewriteEngine on
Redirect to non-www
RewriteCond %{HTTP_HOST} !^(website\.com)?$
RewriteRule (.*) http://website.com/$1 [R=301,L]

就算我注释掉这仍然更改地址

even if i comment out this the address still changes to

http://website.com/sub/

最好的问候中, 亚历山大

Best of regards, Alexander

推荐答案

我会想象这样的事情会工作(未测试):

I would imagine something like this would work (not tested):

Options FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^website\.com
RewriteCond %{HTTP_HOST} ^([^.]+)
RewriteRule \?cat_id=([0-9]+)&photo_id=([0-9]+) http://website.com/$1/$2/
RewriteRule ^/(.*)/(.*)/ /%1.php?cat_id=$1&photo_id=$2 [P]

注:根据文档,有FollowSymLinks需要 是一个选项,您可以覆盖得到重写工作。

Note: according to the documentation, Options FollowSymLinks needs to be an option you can override to get the rewrite to work.

第一的RewriteCond将确保webiste.com主机不重写(但 域像sub.website.com会)。第二个匹配任何东西 可达的主机名的第一个点。这两个必须成功,如果是的话主机 一部分是%1进行访问。

The first RewriteCond will ensure the "webiste.com" host is not rewritten (but domains like sub.website.com will). The second one matches anything up to the first dot of the hostname. Both of these must succeed and if so the host part is accessible in %1.

第一个重写规则重写args设置为PHP脚本的目录路径 (改变上看到的网址浏览器)。接下来的重写规则使用 [P] 标志以代理的形式/ XX / YY的/任何请求%1.PHP(我们的记忆的主机名) 与ARGS传递到PHP脚本。

The first RewriteRule rewrites the args to the php script to the directory paths (a change seen on URL on the browser). The next RewriteRule uses the [P] flag to proxy any requests of the form /xx/yy/ to %1.php (our remembered host name) with the args passed to the php script.

正如我所说,这是没有测试过,但希望它会在正确的方向得到你。

As I've stated, this is not tested, but hopefully it will get you "in the right direction".

编辑:删除了 [R] 从第一个重写规则

removed the [R] from the first rewrite rule.

这篇关于htaccess的和重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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