Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 使用mod rewrite重写url而不重定向_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache 使用mod rewrite重写url而不重定向

Apache 使用mod rewrite重写url而不重定向,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,正在重写此url http://domain.com/embed/slideshow-image-list.js 对此 http://domain.com/code/embed/slideshow-image-list 当前访问代码 RewriteEngine on RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC] RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L] RewriteRule ^embe

正在重写此url

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

http://domain.com/code/embed/slideshow-image-list
当前访问代码

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


我只是想在不重定向的情况下映射它

不要在规则中提供域,只提供路径。对于完整域,它将被重定向

RewriteRule^embed/([^\.]+)\.js$/code/embed/$1[L]

或者,如果生成的路径不是真实的文件,应该由index.php处理,则禁用
[L]
,以便执行下一条规则:

RewriteRule^embed/([^\.]+)\.js$/code/embed/$1

请注意,上面说了以下内容,这似乎表明完整的URL路径是可以的,但我相信它与ServerName相比,不一定是ServerAlias(我不是100%确定,但在进行非重定向重写时,我总是使用路径而不是完整的URL):

绝对URL

如果指定了绝对URL,mod_rewrite将检查主机名是否与当前主机匹配。如果是这样,则会剥离方案和主机名,并将生成的路径视为URL路径。否则,将对给定URL执行外部重定向。要强制外部重定向回当前主机,请参阅下面的[R]标志


哦,如果
/code/embed/slideshow image list
不是一个实际的文件,并且应该由index.php通过以下规则来处理,那么您可能需要删除
[L]
。我更新了答案以反映前面的评论,并从Apache文档中添加了一条注释。您的东西组合修复了它,但这也是一个codeigniter问题,必须为uri_协议更改一个变量,谢谢。