我试图写一个的.htaccess
规则重定向到一个脚本,从而进一步重定向别处。有点像URL shorteners是如何工作的。然而,我不要想地址栏重定向的的.htaccess
部分发生变化。 (这是没关系的脚本重定向到更改的位置。)
I'm trying to write an .htaccess
rule to redirect to a script, which further redirects somewhere else. Kind of like how URL shorteners work. However, I don't want the address bar to change during the .htaccess
part of the redirect. (It's okay for the script redirect to change the location.)
我用的mod_rewrite
,目前正在做这样的:
I'm using mod_rewrite
, currently doing this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /
RewriteRule (.+)$ "?url=$1" [L,R=301]
有没有标志或其它方法,我可以用它来实现我想要做什么?
Is there a flag or another method I can use to achieve what I'm trying to do?
补遗:在Firefox中的重定向正在发生,这就是我想要做的地址栏并没有改变。它只是改变一次,以反映终点。 Safari浏览器改变它的每一步。什么方法可以避免呢?
Addenda: The location bar doesn't change in Firefox as the redirects are happening, which is what I want to do. It just changes once to reflect the end point. Safari changes it at every step. Any way to avoid that?
如果您使用的是研究
标志你告诉的mod_rewrite
一个外部重定向是你想要的,因此,浏览器被要求做一个新的请求,并在地址栏中应相应地改变。
If you are using the R
flag you are telling mod_rewrite
that an external redirect is what you want, therefore the browser is asked to make a new request and the address bar should change accordingly.
没有研究
标记,也没有重定向,但是这是从浏览器中隐藏着一个Apache内部请求重写。因此,地址栏将不会改变。但是,你不能使用内部重定向到外部URI的原因是显而易见的。
Without the R
flag, there is no redirect, but an Apache-internal request rewrite which is hidden from the browser. Thus, the address bar won't change. However, you cannot use internal redirects to external URIs for obvious reasons.
因为你似乎无论如何要使用内部重定向,只是删除研究
标记,它应该工作:
Since you seem to use an internal redirect anyway, just remove the R
flag and it should work:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+)$ ?url=$1 [L]