重写 CI url

发布于 2024-11-07 03:00:49 字数 1187 浏览 1 评论 0原文

我以前从未重写过 URL,除了删除安装的 CodeIgniter 中的 index.php 部分之外,我是通过在 .htaccess 文件中使用复制粘贴的代码片段来实现的。我还没有时间真正了解该代码片段的作用;我基本上对重写 URL 很陌生。

我的网络应用程序有移动版本。我将移动用户重定向到子域:m.myhost.tld。但是,由于我使用(一个)CodeIgniter(安装),因此我必须将这些移动用户发送到特定于移动设备的控制器,在我的例子中是 /mobile/。所以,控制器总是显示在我的地址栏中。

我只是觉得这不是很干净,我正在寻找一种重写 URL 的方法;但说实话,我什至不确定这是否可能......因此我的问题。 我想摆脱 /mobile 控制器部分。这可能吗?

一些示例:

我当前的移动“根”文件夹是

http://m.myhost.tld/mobile

我想将其转换为

http://m.myhost.tld/

目前,当我访问 http://m.myhost.tld/ 时,它会重定向到我的 CodeIgniter 应用程序的默认控制器,该应用程序是“桌面”版本的一部分网络应用程序的。

另一个例子:

转换

http://m.myhost.tld/mobile#mobile/about

http://m.myhost.tld/#mobile/about

I'我不确定我在这里是否有意义。我在脑子里,但就像我说的,我不知道到底什么是可能的。如果用户位于 m 子域中,我想隐藏网址的 /mobile 部分。但是,只有当我们位于 m 子域时,“桌面”版本(位于 www )才不会受到影响。

就像我说过几次一样,我不确定什么是可能的,我正在寻找的东西可能太复杂或诸如此类。我想我会问,因为通过询问来学习是我最擅长的。如果这是一个愚蠢的问题,专业人士先生们,请不要对我太严厉;)

编辑: 我想我会编辑,因为我不想出错。我不一定要寻找我的问题的确切答案。我也欢迎可能指导我找到解决方案的文档/教程/文章。如果我能想出自己的解决方案,我当然会学到更多。

多谢。

I have never before rewritten a URL except for removing the index.php part of my CodeIgniter installs, and that I do by using a copy-pasted snippet in my .htaccess file. I haven't had the time to actually learn about what the snippet does; I'm basically very new to rewriting URLs.

I have a mobile version of my web application. I got as far as redirecting mobile users to a subdomain: m.myhost.tld. However, since I'm using (one) CodeIgniter (install), I have to send these mobile users to a mobile-specific controller, in my case /mobile/. So, the controller always shows up in my address bar.

I just don't think this is very clean, and I'm looking for a way to rewrite the URL; but truth be told, I'm not even sure if this is possible.. hence my question.
I want to get rid of the /mobile controller part. Is this possible?

Some examples:

My current mobile 'root' folder is

http://m.myhost.tld/mobile

I would like to turn this one into

http://m.myhost.tld/

At the moment, when I go to http://m.myhost.tld/, it redirects to the default controller for my CodeIgniter application, which is part of the 'desktop' version of the web app.

Another example:

Turning

http://m.myhost.tld/mobile#mobile/about

into

http://m.myhost.tld/#mobile/about

I'm not sure if I'm making any sense here. I am in my head, but like I said, I don't know what exactly is possible. If the user is on the m subdomain, I want to hide the /mobile part of my URLs. However, only when we're on the m subdomain, so the 'desktop' version (which sits at www ) does not get touched at all.

Like I said a couple of times now, I'm not sure what is possible and what I'm looking for might just be too complex or whatnot. I figured I would ask though, since learning by asking is what I do best. Please don't be too hard on me if this turns out to be a dumb question, sirs professionals ;)

EDIT:
I thought I'd edit because I don't want to come off wrong. I'm not necessarily looking for exact answers to my question. I also welcome documentation/tutorials/articles that might guide me to a solution. If I can manage to come up with a solution of my own, I will of course learn a lot more.

Thanks a lot.

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

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

发布评论

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

评论(2

层林尽染 2024-11-14 03:00:49

这可能是一个太简单的解决方案,但为什么不在你的路由配置中做一些简单的事情,比如

在你的配置中做一些类似的事情

if ($_SERVER['SERVER_NAME'] == 'm.myhost.tld')
    $route['default_controller'] = "mobile";

,这将使默认控制器移动,这样你就不必拥有 /mobile...

正如我所说,也许也是简单的

This could be too simple of a solution but why not in your routing config do something simple like

in your config do something like

if ($_SERVER['SERVER_NAME'] == 'm.myhost.tld')
    $route['default_controller'] = "mobile";

This would make the default controller mobil so you wouldn't have to have /mobile...

As i said maybe too simple

怎言笑 2024-11-14 03:00:49

编辑:不起作用,但也许有人可以将其变成有效的东西

试试这个:

RewriteCond $1!^mobile/
RewriteCond %{HTTP_HOST} ^m\.myhost\.tld
RewriteRule (.*) /mobile/$1 [L]

EDIT: Doesn't work, but maybe someone can turn it into something that does

Try this:

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