重写一个没有 302 重定向的 URL

Rewrite an URL without 302 redirect

我想知道,如何在没有 302 重定向的情况下重写 URL。
该网站的目标是 2 个域。

这是我的.htaccess

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^domain2.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain2.com$
RewriteRule ^([A-Za-z0-9-]+)$ http://domain2.com/url/ [L]

Rewritecond %{HTTP_HOST} domain2.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://domain2.com/soon/ [QSA,L,R=301]

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/ [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/ [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]

当我打电话给我的 shothener http://domain2.com/57b97f2 时,我正在使用 302 重定向重定向到 http://domain2.com/url/57b97f2

如何避免这种不需​​要的 302 重定向?

======= 编辑 ======= :

我的 url() 功能控制器命名为:webadmin

我的路线是:

$route['default_controller'] = 'webadmin';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['(.+)'] = 'webadmin/';

网络管理员控制器:

function url($code)
{
    //do something
}

请尝试以下操作:

Options +FollowSymlinks

RewriteEngine on

# 1. If we're on the root of domain2.com, temporarilty redirect to
#    the `/soon` handler
#    Note: This redirect should really be temporary, as it is a
#          landing page for your soon-to-be-released app/site.

RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$
RewriteRule ^$ /soon [R=302,L]

# 2. If we're on domain2.com, rewrite short URIs to the `/url` handler
#    Note the use of the `N` flag which causes the ruleset to start
#    again from the beginning using the result of the rewrite. This
#    will cause the rewritten URI to be passed to `index.php` (the
#    last RewriteRule).
#    Also added is the NC flag, which may or may not be better than
#    specifying `A-Z` in the pattern's expression.

RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$
RewriteRule ^([a-z0-9-]+)$ /url/ [NC,N]

# 3. Redirect application/system directory requests to index.php

RewriteRule ^(application|system) /index.php?/ [L]

# 4. For everything else (sans files and directories), rewrite to index.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/ [L]

请注意,我已经简化了您的大部分代码。

此外,我还没有对此进行测试,但它应该(理论上)有效。