htaccess:多个子文件夹和网站访问

发布于 2024-10-31 15:20:06 字数 1042 浏览 1 评论 0原文

我无法正确设置 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/blalahttp://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 技术交流群。

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

发布评论

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

评论(2

伤感在游骋 2024-11-07 15:20:06

这应该有效。

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/
RewriteCond %{REQUEST_URI} !^/somefolder/
RewriteCond %{REQUEST_URI} !^/client/blabla/
RewriteRule (.*) /website/$1

# clean urls
RewriteRule ^website/([a-z0-9\-]+)$ website/$1.php

This shoud work.

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/
RewriteCond %{REQUEST_URI} !^/somefolder/
RewriteCond %{REQUEST_URI} !^/client/blabla/
RewriteRule (.*) /website/$1

# clean urls
RewriteRule ^website/([a-z0-9\-]+)$ website/$1.php
墨小墨 2024-11-07 15:20:06

我认为你只需要添加几个条件来排除它们。

RewriteCond %{REQUEST_URI} !^/clients/
RewriteCond %{REQUEST_URI} !^/somefolder/

并将它们放在子文件夹部分的重写规则前面。如果 URI 已包含 /clients//somefolder/,这将阻止它将 /website/ 嵌入到 URI 中

I think you just need to add a couple more conditions to exclude them.

RewriteCond %{REQUEST_URI} !^/clients/
RewriteCond %{REQUEST_URI} !^/somefolder/

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/

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