htaccess:多个子文件夹和网站访问
我无法正确设置 htaccess。目前我的 htdocs 文件夹中有以下情况和文件结构:
- .htaccess
- /website
- /clients/blabla
- /somefolder
正如您可能猜到的,文件夹“website”包含导航到 http://mydomain.com - 这适用于当前的 htaccess:
RewriteEngine on
# remove www
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]
# subfolder
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
RewriteCond %{REQUEST_URI} !^/website/
RewriteRule (.*) /website/$1
# clean urls
RewriteRule ^website/([a-z0-9\-]+)$ website/$1.php
我的问题:虽然我希望我的网站能够像现在这样访问我还希望能够访问 http://mydomain.com/clients/blala 和 http://mydomain.com/somefolder 等...使用我当前的 htaccess 这会导致 404 错误,显示“请求的 URL在此服务器上找不到 /website/clients/blabla。”
我需要在 htaccess 中添加/更改什么才能使其正常工作?
提前致谢
I'm being stuck setting up my htaccess properly. Currently I have the following situation and file structure in my htdocs folder:
- .htaccess
- /website
- /clients/blabla
- /somefolder
As you might guess, the folder "website" contains all the files that should be accessible upon navigation to http://mydomain.com - this works fine with the current htaccess:
RewriteEngine on
# remove www
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]
# subfolder
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
RewriteCond %{REQUEST_URI} !^/website/
RewriteRule (.*) /website/$1
# clean urls
RewriteRule ^website/([a-z0-9\-]+)$ website/$1.php
My problem: While I want my website to be accessible the way it is now I also want to be able to access http://mydomain.com/clients/blala and http://mydomain.com/somefolder etc... With my current htaccess this results in a 404 Error saying "The requested URL /website/clients/blabla was not found on this server."
What do I need to add / change to my htaccess to make this work?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该有效。
This shoud work.
我认为你只需要添加几个条件来排除它们。
并将它们放在子文件夹部分的重写规则前面。如果 URI 已包含
/clients/
或/somefolder/
,这将阻止它将/website/
嵌入到 URI 中I think you just need to add a couple more conditions to exclude them.
And have these in front of your Rewrite rule in the subfolder section. That will stop it embedding
/website/
into the URI if it already contains/clients/
or/somefolder/