0

我已经启动并运行了一个 codeigniter 站点,没有任何问题。现在我需要将一些图像重写为 codeigniter 控制器/方法。

这是我的 .htaccess 文件,工作正常

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|media|static|public)
RewriteRule ^(.*)$ /index.php?/$1 [L]

现在我需要这样的东西来将图像重写为 codeigniter。重写不重定向

RewriteRule ^(media/somefolder/someimage.jpg)$ /some_controller/somemethod?param=value [L]

我添加了以下行(这不是 codeigniter 只是一个常规的 php 文件)只是为了测试以确保 RewriteRule 工作正常并且工作正常

RewriteRule ^(media/somefolder/someimage.jpg)$ public/myphpfile.php?ipath=$1 [L]

但是,如果我尝试以下任何操作,我会得到 codeigniter's page not found 错误页面。

RewriteRule ^(media/somefolder/someimage.jpg)$ /some_controller/somemethod/?ipath=$1 [L]

或者

RewriteRule ^(media/somefolder/someimage.jpg)$ index.php?c=some_controller&m=somemethod&ipath=$1 [L]

我在这里想念什么?

4

1 回答 1

0

仅向特定图像添加例外

添加这样的media规则:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(media/somefolder/someimage.jpg)$ /index.php?/some_controller/somemethod/?ipath=$1 [L]
RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|media|static|public)
RewriteRule ^(.*)$ /index.php?/$1 [L]

为媒体目录中的所有图像添加例外

由于您已过滤掉以忽略media此规则上的目录:

RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|media|static|public)

为了重写media控制器的路径而不是忽略它,请media从中删除规则:

RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|static|public)

添加这样的media规则:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
# removed the media form below rule
RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|static|public)
RewriteRule ^(media/somefolder/someimage.jpg)$ /index.php?/some_controller/somemethod/?ipath=$1 [L]
RewriteRule ^(.*)$ /index.php?/$1 [L]
于 2019-10-01T09:58:38.420 回答