困难的 .htaccess 问题
我有以下目录结构:
主页: /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.com 和 www.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该在两个域中访问同一个博客,因为这会导致内容重复,这对搜索引擎优化不友好。
如果您只需将一个状态为 301 的 uri 重写为另一个 uri 会更好。
告诉我这对你是否有效。我认为由于 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.
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