Rewrite Drupal files directory to sub folder - drupal

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-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/');

Related

How change back url of your site in wordpress

I accidentally added www before url of my local running site for some plugin. than I couldn't access to site again because obviously my local server which is open server don't have www prefix before main path. So I changed back both in my wp-config.php and even in mySql database. In bot places they show the url path without www , but now when I press my site name in admin part its again add back this www so in result browser shows site not found. Can I somehow get rid of www from the path? Thanks
If you have made absolutely sure that ALL domain/URL related records in the database are updated so that there is no www prefix anywhere (especially the wp_options table), the problem most likely lies with the .htaccess file.
For a quick test, find the file called .htaccess in the web root folder of the site and just rename it and then try. If that works, look for something like the following in the .htaccess file:
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
If you find this, change it as follows:
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
Finally, change the file name back to .htaccess and it should work fine.
Edit: In some cases, it may be necessary to clear browser cache/cookies and/or restart the browser/reboot for the changes to take effect.

mod_rewrite does not trigger css to load

I want to redirect all requests to index.php and any %{REQUEST_URI} portion should be passed as an argument to index.php. Also, even if the %{REQUEST_URI} portion points to an existing file/directory, I still want to do the redirect. For example, there is a directory called js in my document root. When I access my site like http://www.example.com/js, then I still want to redirect to http://www.example.com/index.php?uri=js instead of displaying the content of the directory in a browser.
So, I added the following two lines in my .htaccess file.
RewriteEngine On
RewriteRule .* index.php?uri=%{REQUEST_URI} [QSA]
But this does not work.
First, when I specify a path to an existing file, e.g. http://www.example.com/foo.css, it still displays a content of the file in a browser. (What I want is http://www.example.com/index.php?uri=foo.css) Second, when accessing a directory, e.g. http://www.example.com/js, then the redirect happens, but css fails to take effect and my site looks corrupted.
The good news is it works fine if I specify an arbitrary string that does not point to any files/directories in the root. I spent hours trying to debug this, but I have no clue. How would I solve my problems?
FYI, I'm using Apache 2.4.3.
Maybe this following code :
RewriteEngine On
RewriteRule ^index.php?uri=(.*)$ $1 [L]
I don't know if it's that you want.

Static PHP application directory on a wordpress site

I'm having trouble setting up a directory with php files on a wordpress site.
I understand how to use templates to include a custom php file, but what I'm trying to do is access a php file as if wordpress was not installed. Right now when I create a new directory(dir1) and put an index.php file in that folder, then try to view by going to www.test.com/dir1 it shows a bulleted list with links to header, background, and updates with a text input for searching the website at the bottom.
I'm not sure if this is something that needs to be configure in my cPanel or if its a wordpress setting, or even if its an htaccess issue.
Please help me figure out what I need to do, or even at the very least, help me put into words what I'm trying to do. Thanks!
Usually Wordpress installed in the root has no impact at all on whatever is put into non-wp directories. Can you paste your .htaccess file from the root folder? And does your /dir1/ have any .htaccess?
Wordpress has nothing do to with existing folders/files. Here are some steps you may try.
Make sure your /dir1 doesn't have .htaccess or if in case you have and you need it to have it there, continue doing next steps.
Add some inclusions in rewrite engine of your .htaccess file. You may add something like this:
RewriteCond %{REQUEST_FILENAME} !-d and/or RewriteCond %{REQUEST_FILENAME} !-d
or
RewriteCond %{HTTP_HOST} !dir1
I hope this helps.
Bah, I've figured it out.
anytime I would FTP files onto my server, it would make the owner/group "root"
After I used WinSCP to change my users to match each website, it worked perfectly.
cPanel is a pain.

mod_rewrite redirect for site that contains drupal

I am new to using mod_rewrite, so I need an explanation in simple terms. I'm trying to do a redirect for a directory that is in the same directory as a Drupal installation but is not part of Drupal.
For example, a file used to exist at http://mysite.com/events/listen/song.mp3. I rearranged so that the file now resides at http://mysite.com/listen/song.mp3.
I can use the following in mod_rewrite and it works:
RewriteRule ^events/listen/(.+)$ listen/$1 [NC]
However, I'd like to do a real redirect, so that the user sees the new URL instead of the old one. I've tried:
RewriteRule ^events/listen/(.+)$ listen/$1 [R,NC]
and
RewriteRule ^events/listen/(.+)$ http://mysite.com/listen/$1 [R,NC]
Neither of these work. I think it probably has to do with all the rerouting that Drupal is doing, though I do have my rewrite rules before Drupal's in .htaccess. Is there something obvious I'm missing? Or is there a way to allow this to work without messing up what Drupal is doing?
Try
RewriteRule ^events/listen/(.+)$ listen/$1 [R=301,L]

.htaccess - Rewrite a request to one directory before the request is handled by that directory?

I'm trying to exclude all BUT one directory from a rewrite rule. I want the request to be handled by the index.php file in the root directory which will then include the subdirectory's index.php file as part of a script after wrapping it with it's own code.
This is a really strange problem, since I'm trying to wrap Drupal within a Wordpress installation so that the existing site structure can stay put, and I can use a custom template to wrap the drupal output in a slightly customized wordpress theme.
If anybody has any idea how I can do this, I would be very very thankful.
htaccess files seem like arcane arts. Nobody seems to really get them that well, and I am no exception.
RewriteEngine on
RewriteCond $1 !^(drupal_directory|robots\.txt) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
The ! will exclude drupal_directory and robots.txt etc...

Resources