困难的 .htaccess 问题

发布于 2024-10-23 16:51:31 字数 867 浏览 2 评论 0原文

我有以下目录结构:

主页: /domains/example.com/public_html/public/index.php

下面是 .htaccess 脚本,使 www.example.com 能够显示工作正常的主页:

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

现在我想添加一个可通过子域和目录访问的博客,如下所示:blog.example.comwww.example.com/blog

博客索引位于此处:/domains/example.com/public_html/blog/index.php

我应该向 htaccess 添加什么才能启用此功能?

我尝试过:

RewriteCond %{REQUEST_URI} ="blog"
RewriteRule ^.*$ /blog/index.php [L]

但无法查看索引或任何其他测试文件。 blog.example.com 产生“真正的”404 错误,而 www.example.com/blog 显示 Zend 使用的“友好”404 页面。我做错了什么?

I have the following directory structure:

Homepage: /domains/example.com/public_html/public/index.php

Below is the .htaccess script that enables www.example.com to show the homepage which works fine:

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

Now I want to add a blog which is accessible via a subdomain and a directory like this: blog.example.com and www.example.com/blog.

The blog index is located here: /domains/example.com/public_html/blog/index.php

What should I add to htaccess to enable this?

I tried:

RewriteCond %{REQUEST_URI} ="blog"
RewriteRule ^.*$ /blog/index.php [L]

but the index or any other test file can't be viewed. blog.example.com produces a "real" 404 error and www.example.com/blog displays our "friendly" 404 page that Zend uses. What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

徒留西风 2024-10-30 16:51:31

您不应该在两个域中访问同一个博客,因为这会导致内容重复,这对搜索引擎优化不友好。

如果您只需将一个状态为 301 的 uri 重写为另一个 uri 会更好。

RewriteCond %{HTTP_HOST} = ^www\.somedomain\.de$
RewriteRule /blog/(.*) http://blog\.somedomain\.de/$1 [L,R=301]

RewriteCond %{HTTP_HOST} = ^blog\.somedomain\.de$
RewriteRule ^.*$ /blog/index.php [L]

告诉我这对你是否有效。我认为由于 RewriteCond,第二条规则不应与第一条规则冲突。无论如何,我只是想帮忙。我没有测试过这个。如果第一次尝试不起作用,请不要投票给我:)

和平!

编辑:在此示例中,我使用 blog.somedomain.de 作为您博客的唯一可能地址。 somedomain.de/blog/ 将被重定向到 blog.somedomain.de

You should not make a single blog accessible at two domains, because this leads to doublicate content what is not seo friendly.

It would be better if you just rewrite one uri with a 301 status to the other one.

RewriteCond %{HTTP_HOST} = ^www\.somedomain\.de$
RewriteRule /blog/(.*) http://blog\.somedomain\.de/$1 [L,R=301]

RewriteCond %{HTTP_HOST} = ^blog\.somedomain\.de$
RewriteRule ^.*$ /blog/index.php [L]

Tell me if this worked for you. I think the second rule should not conflict with the first one due to the RewriteCond. Anyway, I am just trying to help. I have not tested this. If it does not work the 1st try, plz do not vote me down :)

peace!

EDIT: In this example I used blog.somedomain.de as the only possible address for your blog. somedomain.de/blog/ will be redirected to blog.somedomain.de

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文