开发者

Rewrite Drupal files directory to sub folder

开发者 https://www.devze.com 2023-02-10 04:57 出处:网络
I am \'merging\' two Drupal sites into one multisite installation. But one of the sites has the files saved at <drupal root>/files while the other one saves them at <drupal root>/files/sit

I am 'merging' two Drupal sites into one multisite installation. But one of the sites has the files saved at <drupal root>/files while the other one saves them at <drupal root>/files/site-2 (which actually is a symlink to <drupal root>/sites/site-2/files). Now I'm looking for a way to 'merge' them without loosing the url structure of my site-1, i.e. I want

http://site开发者_Go百科-1.com/files to display http://site-1/files/site-1

and keep http://site-2.com/files/site-2 as it was.

I imagine that this can be done through a simple .htaccess mod_rewrite operation, but I don't know much about that. I was trying

RewriteCond %{HTTP_HOST} site-1.com  
RewriteRule ^/files(.*)?$ /files/site-1$1 [NC]

but that doesn't seem to work. Could somebody help me?


Classic: The server configuration wasn't correct so that the directives didn't work. Grrr. My solution is now like I said in my first 'answer': Change the paths to use the sub directory and then redirect old files to that folder:

RewriteCond %{HTTP_HOST} site-1.com 
RewriteCond %{REQUEST_URI} !^/files/site-1/.*$ 
RewriteRule ^files/(.*)$ /files/site-1/$1 [L,R=301]

I think internal Drupal paths don't work with rewrites (for example imagecache). That's why I chose this option.

fyi: The replace stuff I used to change the paths in the database is this (in phpmyadmin):

UPDATE files SET filepath = REPLACE(filepath,'files/','files/site-1/'); 
UPDATE node_revisions SET body = REPLACE(body,'src="/files/','src="/files/site-1/'); 
UPDATE node_revisions SET teaser = REPLACE(teaser,'src="/files/','src="/files/site-1/'); 
UPDATE boxes SET body = REPLACE(body,'src="/files/','src="/files/site-1/');
0

精彩评论

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