htaccess 和重写 [英] htaccess and rewriting

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

问题描述

我刚刚在我的网站上创建了一个子域,主要是因为我想要一个特定的地址.

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/username/public_html/sub/

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/

当我输入子域地址时,地址突然变为http//website.com/sub/

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

如何保留子域地址?

为丹尼斯

我有一个规则,将所有 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/

最好的问候,亚历山大

推荐答案

我认为这样的事情会起作用(未测试):

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]

注意:根据文档,Options 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.

第一个RewriteRule将php脚本的args重写到目录路径(在浏览器上的 URL 上看到的更改).下一个 RewriteRule 使用 [P]将/xx/yy/形式的任何请求代理到 %1.php(我们记住的主机名)的标志将参数传递给 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天全站免登陆