Ignore rewriting a directory is not working properly - apache

I have a weird situation where a rule is working on a different domain with the same host but it won't work on a specific domain.
I have 2x Bluehost accounts, they are a standard cheap shared hosting provider.
On account #1 I have a single hosted account which has 4 domain names. 1 domain is the primary domain (loads off the /public_html/ directory of the account) and 3 add-on domains which are just folders inside of /public_html/.
On account #1 I have this in my .htaccess file:
RewriteCond %{REQUEST_FILENAME} !-d
That is located directly under where I ignore rewriting some file extensions and after that I have a bunch of url rewrite rules which are all working.
On account #1 this all works fine.
On account #2 I have the same exact setup but the add-on domains are throwing error 500s when accessing them, it also does not add error.log entries in the folder of the files and I tested the domain without rewriting and it works fine. They are accessible through standard urls (www.example.com) so it's not like it's a sub-domain or anything.
This add-on domain in this case is very basic. It's just a single page domain with no rewriting rules. If I delete the .htaccess from the primary domain then the sub domain works.

Well, that was quick. In the add-on domain I did NOT have an .htaccess file. I figured this would be ok because I wasn't doing any re-writing.
Apparently it does not work like that. I added an .htaccess to that add-on domain's folder and added this on top like usual:
RewriteEngine On
Now both domains are working as intended.

Related

Howto use path/directory outside the domain root via symlink without access to domain config?

I am working an a shared hosting plattform which does not allow to edit or access the Apache config file.
The goal is to access the same files from two different domains which point to different domain roots:
test.example.com ---> /test_root/web
public.example.com ---> /public_root/web
Now I would like to access the same files using test.example.com/some/files/... and public.example.com/some/files/...
Of course I could simply copy the files to /test_root/web/some/files/... and to /public_root/web/some/files/... but this obviously just an example. In reality the files are a helpdesk system which should be integreated both into the test- and public-site. Copying the files would include maintaining two different systems, etc.
The goal is, to place the the files somewhere outside the two domain roots and make them available from both domains:
/test_root/web/some/files ---> /path/to/some/files
/public_root/web/some/files ---> /path/to/some/files
I created symlink to achive this (ln -s ...) but this does not work out. When I access on of the domains (e.g. test.example.com/some/files) I only get a blank page without any information what whent wrong.
I assume that the Apache is not configured to follow the symlinks. Without access to the Apache config I can neither check nor fix it.
Adding Symlinks to .../web/.htacess does not make any difference:
// test_root/web/.htaccess
Options +FollowSymLinks
So the question is: How can I make files outside the domain root available within a domain? Is this even possible? Is this possible using symlinks?
Add this in you .htaccess file.
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} test.example.com/path/to/files [NC]
RewriteRule ^(.*)$ http://public.example.com/path/to/files [R=301,NC]
Test out this code. /path/to/files must be under /public_root/web/.
Something like /public_root/web/path/to/files/

htaccess affecting addon domain

I have hosted a few sites on a Hostgator server. I have an htaccess for the main domain, limiting the access from a certain set of IPs. the main domain is in the root folder.
I have another website in a sub-folder which is being affected by the main htaccess file for ip block. I want that the ip block only goes for the main domain and none of the addon domains.
Please advice. I have read a lot of similar threads but the solution mentioned hasn't worked. The solution I found was adding the following code to the root htaccess file -
RewriteCond %{HTTP_HOST} ^(www.)?addon_domain.com
Rewriterule .* - [L]
I did replace the addon_domain with the actual domain with the correct TLD. When I add this, I get a 500 error.
It may have been the simplest of solution but for some reason, I couldn't find the answer online. One of my friends suggested to just use allow from all in the htaccess of the addon domain and it now works. :)

Generic .htaccess for multiple websites stored in subdirectories

My development environment is set up for using a single host (localhost). I am developing multiple websites on my machine, each stored under its own directory like this:
/var/www/site1
/var/www/site2
...
The document root is set to /var/www on my machine.
I am using URL rewriting for most of these websites and most of the .htaccess files will rewrite a sub-directory to GET parameters in different ways like this:
http://localhost/site1/home/red -> http://localhost/site1/index.php?page=home&p1=red
http://localhost/site2/index/param1/param2/param3 -> http://localhost/site2/index.php?page=index&p1=param1&p2=param2&p3=param3
I also tend to copy some of these websites under different directories and, when I do that, I have to make a lot of changes in the .htaccess files for the website that I'm copying.
I would like to know if there is a way to define a constant that contains the website's root directory (not the host's document root) and how can that be used with the rewrite rule so that I would need to change only one line of code (setting this constant to a different value) when copying a website.
Putting this in a different form, is there a way to perform rewrites that relate to a website root instead of a host / %{HTTP_HOST} (i.e. the "host" for the website being localhost/site1 instead of localhost) and how can this be done?
I have tried removing the host from each request at the beginning of the script and prepending it back at the end of the script, but this does not work with rewrite rules that use the [L] option.
Thank you!
Regards,
Lucian
You could make an htaccess file with rules like this:
RewriteEngine On
RewriteBase /site1/
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+) index.php?page=$1&p1=$2&p2=$3&p4=$4 [L,QSA]
And put this in the directory /var/www/site1, and if you want for it to apply to site2, change the RewriteBase and put the rules in /var/www/site2.

Tricky wordpress setup with redirect from another server

I could use some advice as to how to migrate from my local staging server to my production server. Its a rather tricky setup so bare with my as I try to describe it.
I have my site set up and working great at the root of a staging subdomain on my personal server.
Staging: staging.mydomain.com
later this week I'm going to be moving it to a new production server on Rackspace which currently has no domains attached to it (is just an IP address). The clients is redirecting a folder to the new rackspace server.
http://www.clientsdomain.com/subfolder/
This will be where the site lives. But clientsdomain.com is a different server somewhere else in the world (not at rackspace). they will be redirecting traffic to that url to the new rackspace server.
So my questions are:
my working staging set up for wordpress is at the root of my personal servers subdomain. How should I set it up on rackspace? At the root of the ip address? or within a subfolder to mimic the domain setup for any relative links.
The reason I ask is that I thought i had this set up properly....But...
I went ahead and attempted to move the site onto my Rackspace server into a dev folder. My client set up a dev url
http://www.clientsdomain.com/dev/subfolder/
Anyone visiting that url will get redirected to my server (my rackspace server simply has an ip address)
the sites front end works with absolute urls. But where things start to fail is within wp-admin. If for example i'm on the General Settings page and click save. It saves the data and then redirects to /wp-admin/... instead of /dev/subfolder/wp-admin/. Since that folder doesn't exist it goes to my clients 404 page.
Also, going to
http://www.clientsdomain.com/dev/subfolder/wp-admin ends on the clients servers 404 page but...
http://www.clientsdomain.com/dev/subfolder/wp-admin/ (with slash) works properly.
The way I moved the site to Rackspace from my dev folder was to change the URLs in wp-admin on my server (which was staging.mydomain.com) to
http://www.clientsdomain.com/dev/subfolder/
I then saved those settings, downloaded the db and site files and uploaded the files and database to rackspace and changed the wp-config file to match the rackspace db.
This is my current htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I would REALLY appreciated some guidance here. supposed to be going live on Tuesday.
Thanks!
Fish
I recently setup a WordPress installation on a standard domain (www.domain.com) but had to move it over to another domain which had a subdomain (blog.newdomain.com). I found I was experiencing very similar problems to you, especially with wp-admin redirecting to the previous domain which no longer existed.
I came across a handy search and replace tool for MySQL databases (available at http://interconnectit.com/124/search-and-replace-for-wordpress-databases/) and replaced all instances of the original www.domain.com with the new blog.newdomain.com and it corrected all my issues.
I hope this information will help you.
It's usually the options table that causes the issue. Executing
update wp_options set option_value = replace(option_value, 'old_url', 'new_url');
As direct SQL on the DB should do the trick (replacing old_url and new_url with the correct urls).
Another path would be to define these two WP constants in your wp-config.php file, which will override the DB setting for the site URLs:
define('WP_HOME','http://sitehomeurl');
define('WP_SITEURL','http://siteurl');
And of course the caveat to back up your DB before running SQL against it applies.

How do I use Apache mod_rewrite > to redirect a Subdirectory to a Domain (On a Subdomain)?

I have a site on a staging subdomain:
http://sd1.domain1.com/subdir/category-1/
Where 'subdir' is the subdirectory where I'm holding open source (let's say WordPress) files.
The URL that I want on staging should be:
http://sd1.domain1.com/category-1/
What the Final URL should be once I migrate everything from my subdomain to the client's domain:
www.domain2.com/category-1/
So, essentially what I need is the Regular Expression to use in my .htaccess file.
It needs to:
remove the 'subdir' subdirectory from the URL
work on a subdomain (without the '.com')
work on a production domain (with the '.com'
work with and without SSL (https:// + http://)
Thanks!
If it's WordPress,
RewriteRule .* subdir/index.php [L]
You don't have to write anything for requirements 2, 3, 4. You're rewriting request URIs, the host and protocol are unexamined and unchanged.
If it's not WordPress, then you might need to do something different.