.htaccess 问题、虚拟子域和代码点火器
基本上我的问题是这样的。我已经建立了一个接受通配符子域的系统,并将它们重写为单个 CodeIgniter 安装。有一个称为调度程序的控制器,它接受所需的参数,并传递 URL 中使用的子域。
我的问题是这样的:我需要创建符合 CodeIgniter 的 URL 结构的 RewriteRules。目前我有这个:
RewriteEngine On
# Extract the subdomain part of domain.com
RewriteCond %{HTTP_HOST} ^([^\.]+)\.ev-apps\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# Check that the subdomain part is not www and ftp and mail
RewriteCond %1 !^(www|ftp|mail)$ [NC]
# Redirect all requests to a php script passing as argument the subdomain
RewriteRule ^/(.*)/(.*)$ /dispatcher/run_app/$1/$2/%1 [L,QSA] # First is app name, then site, then action
RewriteRule ^/(.*)/(.*)/(.*)$ /dispatcher/run_app/$1/$2/$3/%1 [L,QSA] # First is app name, then site, then action, then any passed data.
它适用于遵循此格式的 URL“http://example .ev-apps.com/app/method/1”,但不适用于“ http://example.ev-apps.com/app/method”。似乎优先级都是错误的,但理想情况下我想要一个适用于任意数量的段的解决方案,例如:“http://example.ev-apps.com/app/method/1/2/3/4/5/6 /7/8/9 等。
任何帮助将不胜感激。
basically my problem is this. I have set up a system that accepts wildcard subdomains, and rewrites them to a single CodeIgniter installation. There is a controller called dispatcher that takes the arguments that it requires, as well as being passed the subdomain being used in the URL.
My problem is this: I need to create RewriteRules that conform with CodeIgniter's URL structure. Currently I have this:
RewriteEngine On
# Extract the subdomain part of domain.com
RewriteCond %{HTTP_HOST} ^([^\.]+)\.ev-apps\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# Check that the subdomain part is not www and ftp and mail
RewriteCond %1 !^(www|ftp|mail)$ [NC]
# Redirect all requests to a php script passing as argument the subdomain
RewriteRule ^/(.*)/(.*)$ /dispatcher/run_app/$1/$2/%1 [L,QSA] # First is app name, then site, then action
RewriteRule ^/(.*)/(.*)/(.*)$ /dispatcher/run_app/$1/$2/$3/%1 [L,QSA] # First is app name, then site, then action, then any passed data.
It works fine for URLs that follow this format "http://example.ev-apps.com/app/method/1", but not for "http://example.ev-apps.com/app/method". It seems the precedence is all wrong, but ideally I want a solution that will work for any number of segments, for example: "http://example.ev-apps.com/app/method/1/2/3/4/5/6/7/8/9, etc.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过使用以下指令解决了这个问题:
然后在我的调度程序操作中使用以下代码:
感谢您的阅读,如果您这样做了!
I solved this issue by using the following directive:
And then using the following code in my dispatcher action:
Thanks for reading, if you did!