通过 .htaccess 仅重写特定 URL

发布于 2024-09-28 02:10:20 字数 495 浏览 1 评论 0原文

我为我的网站创建了一个前端控制器。我想通过这个前端控制器将所有请求传递到网站。现在我还在网络根目录中安装了一些其他软件,现在我正在添加这些文件夹以通过 .htaccess 忽略,以便它们的请求也不会发送到前端控制器。我正在做类似下面的事情,

  RewriteEngine On
  RewriteCond $1 !^(folder1|folder2|folder3|robots\.txt)
  RewriteRule ^(.*)$ index.php [QSA,L]

这目前有效,但是有没有办法仅添加特定域或文件夹的请求以通过index.php传递,例如:www.mysite.com或www.mysite.com/folder4或mysite.com。

这样,每当创建新文件夹时,我就不必不断添加要忽略的文件夹。

谢谢。

编辑:我会尝试使其变得更简单。我希望对一个特定文件夹和主站点的所有请求都通过前端控制器。除此之外,所有请求都应照常处理

I have created a front controller for my website. I want to pass all requests to the website through this front controller. Now I also have some other software installed in the web root and right now I am adding those folders to ignore via .htaccess so that their requests also don't go to front controller. I am doing something like below,


  RewriteEngine On
  RewriteCond $1 !^(folder1|folder2|folder3|robots\.txt)
  RewriteRule ^(.*)$ index.php [QSA,L]

This works for now, but is there a way to add requests only for specific domain or folder to get passed through index.php for Eg: www.mysite.com or www.mysite.com/folder4 or mysite.com.

This way I don't have to keep adding folders to ignore whenever a new one is created.

Thanks.

EDIT: I'll try and make it simpler. I want all the requests for one specific folder and main site to go through a front controller. Other than these, all requests should be processed as usual

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

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

发布评论

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

评论(2

渡你暖光 2024-10-05 02:10:20

您可以使用这些条件来排除任何可以映射到现有文件或目录的请求:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

You could use these conditions instead to exclude any request that can be mapped onto existing files or directories:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
梦里寻她 2024-10-05 02:10:20

您可以使用 SERVER_NAME 变量:

RewriteCond %{SERVER_NAME} ! ^(www\.)?mysite\.com$

You can use the SERVER_NAME variable:

RewriteCond %{SERVER_NAME} ! ^(www\.)?mysite\.com$
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文