开发者

.htaccess rewrite rule to add a string in the middle of the URL

开发者 https://www.devze.com 2023-01-03 10:26 出处:网络
Using a .htaccess rewrite rule, I need to add \"?q=\" before the path on any URL\'s containing the word \"imagecache\"

Using a .htaccess rewrite rule, I need to add "?q=" before the path on any URL's containing the word "imagecache"

Therefore, if the URL is:

http://mysite.com/sites/default/files/imagecache/myimage.开发者_Python百科jpg

...then it will really try:

http://mysite.com/?q=sites/default/files/imagecache/myimage.jpg

But that will ONLY happen if the URL contains "imagecache." Otherwise, it does no rewriting.

Also, this will only happen if /sites/default/files/imagecache/myimage.jpg isn't already an existing image file. I believe I can do that using:

RewriteCond %{REQUEST_FILENAME} !-f

...right? It's just the first part that I can't figure out.


Something like this?:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*imagecache.*)$ /?q=$1 [L,QSA]


RewriteRule ^mysite.com/(.*)/imagecache/(.*)$ mysite.com/?q=$1/imagecache/$2
0

精彩评论

暂无评论...
验证码 换一张
取 消