.htaccess 问题、虚拟子域和代码点火器

发布于 2024-09-14 12:24:43 字数 1286 浏览 3 评论 0原文

基本上我的问题是这样的。我已经建立了一个接受通配符子域的系统,并将它们重写为单个 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 技术交流群。

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

发布评论

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

评论(1

笑看君怀她人 2024-09-21 12:24:44

我通过使用以下指令解决了这个问题:

RewriteRule ^(.*)$ /dispatcher/run_app/%1/$1 [L,QSA] 

然后在我的调度程序操作中使用以下代码:

$args = func_get_args();

$site_subdomain = $args[0];
$app_name = $args[1];
$action = $args[2];
$input = (isset($args[3]) ? $args[3] : '');

感谢您的阅读,如果您这样做了!

I solved this issue by using the following directive:

RewriteRule ^(.*)$ /dispatcher/run_app/%1/$1 [L,QSA] 

And then using the following code in my dispatcher action:

$args = func_get_args();

$site_subdomain = $args[0];
$app_name = $args[1];
$action = $args[2];
$input = (isset($args[3]) ? $args[3] : '');

Thanks for reading, if you did!

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