需要在 Kohana 中重写移动控制器

发布于 2024-09-18 07:02:18 字数 926 浏览 2 评论 0原文

我正在尝试将 htaccess mobile.domain.com/mobile/function 重写

mobile.domain.com/function

我认为下面的内容可以工作,但它认为该函数是一个控制器。

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
 Order Deny,Allow
 Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

# Rewrite for Mobile
RewriteCond     %{HTTP_HOST}    ^mobile\.domain\.com$ [NC]
RewriteCond     %{REQUEST_URI}  !mobile [NC]
RewriteCond     %{REQUEST_FILENAME} !-f
RewriteRule     ^(.*)$          /mobile/$1 [L]

I am trying to rewrite in htaccess

mobile.domain.com/mobile/function into mobile.domain.com/function

I thought the below would work but it thinks that the function is a controller.

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
 Order Deny,Allow
 Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

# Rewrite for Mobile
RewriteCond     %{HTTP_HOST}    ^mobile\.domain\.com$ [NC]
RewriteCond     %{REQUEST_URI}  !mobile [NC]
RewriteCond     %{REQUEST_FILENAME} !-f
RewriteRule     ^(.*)$          /mobile/$1 [L]

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

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

发布评论

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

评论(1

雪若未夕 2024-09-25 07:02:18

尝试

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

# Rewrite for Mobile
RewriteCond     %{HTTP_HOST}    ^mobile\.domain\.com$ [NC]
RewriteCond     %{REQUEST_URI}  !mobile [NC]
RewriteCond     %{REQUEST_FILENAME} !-f
RewriteRule     ^(.*)$          /mobile/$1 [L]

编辑交换:

好的,尝试这个而不是你当前拥有的:

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
 Order Deny,Allow
 Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

# Rewrite for Mobile
RewriteCond     %{HTTP_HOST}    ^mobile\.domain\.com$ [NC]
RewriteCond     %{REQUEST_URI}  !mobile [NC]
RewriteCond     %{REQUEST_FILENAME} !-f
RewriteRule     ^(\w+)$          /mobile/$1


# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

Try swapping

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

with

# Rewrite for Mobile
RewriteCond     %{HTTP_HOST}    ^mobile\.domain\.com$ [NC]
RewriteCond     %{REQUEST_URI}  !mobile [NC]
RewriteCond     %{REQUEST_FILENAME} !-f
RewriteRule     ^(.*)$          /mobile/$1 [L]

EDIT:

Okay, try this instead of what you currently have:

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
 Order Deny,Allow
 Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

# Rewrite for Mobile
RewriteCond     %{HTTP_HOST}    ^mobile\.domain\.com$ [NC]
RewriteCond     %{REQUEST_URI}  !mobile [NC]
RewriteCond     %{REQUEST_FILENAME} !-f
RewriteRule     ^(\w+)$          /mobile/$1


# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文