使用mod-rewrite不进行重新定向重写URL重写、mod、rewrite、URL

2023-09-02 09:51:54 作者:青山独归晚

这个网址被重写

http://domain.com/embed/slideshow-image-list.js

http://domain.com/code/embed/slideshow-image-list

目前的htaccess code

current htaccess code

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
RewriteRule ^embed/([^.]+).js$ http://domain.com/code/embed/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]

目前其正确改写,但是如果您访问的.js URL,那么重定向到完整的URL。

its currently rewritten correctly, but if you visit the .js url it redirects to the full url.

即时寻找只是映射它不进行重新定向

im looking just to map it without redirection

推荐答案

不提供在规则领域,人的路。随着全域将会被重定向。

Don't supply the domain in the rule, just the path. With the full domain it will be redirected.

重写规则^嵌入/([^ 。] +)。JS / code /嵌入/ $ 1 [L]

另外,如果生成的路径是不是一个真正的文件,应由index.php文件进行处理,STIP关闭 [L] ,以便下一个规则将被执行

Alternately, if the resulting path is not a real file and should be handled by index.php, stip off the [L] so that the next rule will be executed:

重写规则^嵌入/([^ 。] +)。JS / code /嵌入/ $ 1

请注意,该 mod_rewrite的导向下的说,这似乎表明,充分URL路径是好的,但我相信它比较对服务器名,不一定ServerAlias​​(我不是100%肯定,但我一直在使用这样的路径,而不是完整的URL非重定向重写):

Note that the mod_rewrite guide says the following, which would seem to indicate that the full URL path is okay, but I believe it compares against ServerName, not necessarily ServerAlias (I'm not 100% sure about that, but I've always used paths rather than full URLs in doing non-redirect rewrites):

绝对URL

如果指定一个绝对的URL,mod_rewrite的检查,看主机名是否在当前主机相匹配。如果是这样,该方案和主机名被剥离出来,生成的路径将被视为一个URL路径。否则,执行用于给定URL的外部重定向。要强制外部重定向到当前主机,请参见下面的[R]标志。

If an absolute URL is specified, mod_rewrite checks to see whether the hostname matches the current host. If it does, the scheme and hostname are stripped out and the resulting path is treated as a URL-path. Otherwise, an external redirect is performed for the given URL. To force an external redirect back to the current host, see the [R] flag below.