通过 .htaccess 仅重写特定 URL
我为我的网站创建了一个前端控制器。我想通过这个前端控制器将所有请求传递到网站。现在我还在网络根目录中安装了一些其他软件,现在我正在添加这些文件夹以通过 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用这些条件来排除任何可以映射到现有文件或目录的请求:
You could use these conditions instead to exclude any request that can be mapped onto existing files or directories:
您可以使用 SERVER_NAME 变量:
You can use the SERVER_NAME variable: