Apache RewriteEngine is not working with virtual host setup - mod-rewrite

I have a basic virtual host setup enabled on my machine, and it works fine when I just type in the server name. However, when I include "RewriteEngine On" it kills it. Yes, I do have the rewrite module installed, and yes, I have restarted apache. I'm not actually attempting any rewrite rules yet, because just the act of turning the thing on is enough to make it stop working. Any clue as to what's going on? Seems like if the module is included, this ought to work. What am I forgetting? Here's what I've got in my virtual host file
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "C:/www/mysite/public/"
ServerName mysite
RewriteEngine on
<Directory "C:/www/mysite/public/"
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
When I remove the "RewriteEngine on" line, everything works. When I put it back in, it breaks. I could understand if I had some weird rule in there, but simply turning it on shouldn't break anything.

Perhaps mod_rewrite isn't enabled in your setup? You can try to put the RewriteEngine On line inside an test like so
<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>

I assume you an Ubuntu-like system.
Go to /etc/apache2/sites-available/your_site.conf
Open your_site.conf using your favorite text editor.
Add/Update the Directory section as below
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Save it and restart apache.

Related

Run Laravel on another URL root path http://example.xom/laravel_proj1 and http://example.xom/laravel_proj2

I want to use Laravel projects at the same time. How you can do it? For example one project at
http://example.xom/laravel_proj1
and another on
http://example.xom/laravel_proj2
Configuration: Laravel 7 / 8 and Apache
Update: This is 2 different Projects. But are there some problems if I use this 2 equals Projects. Upsides of MySQL Datables of course.
File: /opt/bitnami/apache2/conf/vhosts/APPNAME-vhost.conf
<VirtualHost 127.0.0.1:80 _default_:80>
ServerAlias *
DocumentRoot /opt/bitnami/projects/APPNAME/public
<Directory "/opt/bitnami/projects/APPNAME/public">
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Usually you work with subdomains to have multiple laravel projects running at the same time. This means that one instance runs at first.example.com and the other at second.example.com. In my opinion what you are trying is more a workaround if you only have one vhost running.
So I would have two vhost files like you have now. One like:
<VirtualHost 127.0.0.1:80 _default_:80>
ServerAlias first.example.com
DocumentRoot /opt/bitnami/projects/first/public
<Directory "/opt/bitnami/projects/first/public">
...
</Directory>
</VirtualHost>
and
<VirtualHost 127.0.0.1:80 _default_:80>
ServerAlias second.example.com
DocumentRoot /opt/bitnami/projects/second/public
<Directory "/opt/bitnami/projects/second/public">
...
</Directory>
</VirtualHost>
Then you would add both subdomains to your hosts file. I don't know where that one is located but in there you would have to add:
127.0.0.1 first.example.com
127.0.0.1 second.example.com
This is not exactly how I do it now, but I think it could be a good starting point. You also need to activate your vhosts and restart apache.

Getting mod_wsgi(reviewboard) and mod_php(wordpress) working on same servername but different path

I'm trying to get my wordpress site as well as my reviewboard site working under the same domain name.
Ex:
www.mysite.com (this is where i host my wordpress site)
www.mysite.com/reviewboard (this is where I want to host my reviewboard site)
I can get one or the other to work depending on my httpd-vhosts.conf file. However, I cannot get both to work(this is where I need your help!).
This is how I host my wordpress site:
<VirtualHost *:80>
ServerAdmin myemail#gmail.com
DocumentRoot "/opt/local/apache2/htdocs/mysite"
ServerName www.mysite.com
ErrorLog "/opt/local/apache2/logs/mysite.com-error_log"
CustomLog "/opt/local/apache2/logs/mysite.com-access_log" common
</VirtualHost>
This is how I host my reviewboard site(which then breaks my wordpress site):
<VirtualHost *:80>
ServerName www.mysite.com
DocumentRoot "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs"
# Error handlers
ErrorDocument 500 /errordocs/500.html
WSGIPassAuthorization On
WSGIScriptAlias "/reviewboard" "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/reviewboard.wsgi/reviewboard"
<Directory "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs">
AllowOverride All
Options -Indexes +FollowSymLinks
Allow from all
</Directory>
# Alias static media requests to filesystem
Alias /reviewboard/media "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/media"
Alias /reviewboard/static "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static"
Alias /reviewboard/errordocs "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/errordocs"
Alias /reviewboard/favicon.ico "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static/rb/images/favicon.png"
</VirtualHost>
So, now I want to be able to figure out how to combine these somehow so I can have reviewboard hosted at the path specified above without breaking my wordpress site. I tried using the Alias command as mentioned here: http://stackoverflow.com/questions/1553165/multiple-django-sites-with-apache-mod-wsgi
and here
https://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines
However I can't get it to work. Here's my WIP. If you can be very specific as what I need to do in order to change this so it works that would be great since I'm new to this kind of stuff. Thanks!
<VirtualHost *:80>
ServerName www.mysite.com
DocumentRoot "/opt/local/apache2/htdocs/mysite"
# Error handlers
#hmm not sure where to put this since my document root is different??????
#ErrorDocument 500 /errordocs/500.html
WSGIPassAuthorization On
Alias /reviewboard/ /opt/local/apache2/htdocs/mysite/reviewboard/htdocs/
<Directory "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs">
Options ExecCGI
SetHandler wsgi-script
AllowOverride All
Options -Indexes +FollowSymLinks
Allow from all
</Directory>
# Alias static media requests to filesystem
# Since I added the alias command above these are complaining about
#overlapping an earlier alias when I restart my apache server????
Alias /reviewboard/media "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/media"
Alias /reviewboard/static "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static"
Alias /reviewboard/errordocs "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/errordocs"
Alias /reviewboard/favicon.ico "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static/rb/images/favicon.png"
</VirtualHost>
If you're using the same domain for both, you can't use different VirtualHost sections for both. So first off, you have to merge both configurations into a single VirtualHost section. I'd start with the WordPress config, then add a few bits for ReviewBoard:
<VirtualHost *:80>
ServerAdmin myemail#gmail.com
DocumentRoot "/opt/local/apache2/htdocs/mysite"
ServerName www.mysite.com
ErrorLog "/opt/local/apache2/logs/mysite.com-error_log"
CustomLog "/opt/local/apache2/logs/mysite.com-access_log" common
WSGIPassAuthorization On
WSGIScriptAlias /reviewboard /opt/local/apache2/htdocs/mysite/reviewboard/rb.wsgi
<Directory /opt/local/apache2/htdocs/mysite/reviewboard>
Order deny,allow
Allow from all
</Directory>
Alias /reviewboard/media "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/media"
Alias /reviewboard/static "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static"
Alias /reviewboard/errordocs "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/errordocs"
Alias /reviewboard/favicon.ico "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static/rb/images/favicon.png"
</VirtualHost>
You need to create a WSGI script (but you should already have that). You might want to put it in a different path than what I put in the config here, so your permissions are more secure.
Using a combination of what djc wrote and some of my tinkering here's the working version so that:
www.mysite.com (wordpress site loads correctly)(mod_php)
www.mysite.com/reviewboard (reviewboard site loads correctly)(mod_wsgi)
Important make sure you clear your browser cache every time you restart your apache server as I kept falling into the trap of it showing incorrect data since I forgot to do that.
Important2 Make sure the "/reviewboard" follows the "reviewboard.wsgi" to become "reviewboard.wsgi/reviewboard" otherwise it will not work and gives a 404 error!
Here's the working version:
<VirtualHost *:80>
ServerAdmin myemail#gmail.com
ServerName www.mysite.com
DocumentRoot "/opt/local/apache2/htdocs/mysite"
ErrorLog "/opt/local/apache2/logs/mysite-error_log"
CustomLog "/opt/local/apache2/logs/mysite-access_log" common
WSGIPassAuthorization On
WSGIScriptAlias /reviewboard /opt/local/apache2/htdocs/mysite/reviewboard/htdocs/reviewboard.wsgi/reviewboard
<Directory /opt/local/apache2/htdocs/mysite/reviewboard>
Allow from all
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
# Alias static media requests to filesystem
Alias /reviewboard/media "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/media"
Alias /reviewboard/static "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static"
Alias /reviewboard/errordocs "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/errordocs"
Alias /reviewboard/favicon.ico "/opt/local/apache2/htdocs/mysite/reviewboard/htdocs/static/rb/images/favicon.png"
</VirtualHost>

Local testing: make a second DocumentRoot in XP?

I'm trying to give my computer the priority on a domain name that isn't being broadcast: www.mythiddomain.com. I set up my vhosts file, like so:
<VirtualHost *:80>
ServerName mythirddomain.com
DocumentRoot "C:/www"
<Directory "C:/www">
Options +Indexes FollowSymlinks +ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I tried editing my hosts file in multiple ways, including 127.0.0.1 mythirddomain.com and 198.168.1.2 mythirddomain.com, but I was just jabbing blind. I'm not sure what the next step is, after changing the vhosts file.
Action:
Browse to mythirddomain.com.
Expected result:
Get my index.php file.
Actual result:
Get inuit.com (they own mythirddomain.com).
Edit the following file:
%SystemRoom%\system32\drivers\etc\hosts
Add a line like this:
127.0.0.1 mythirddomain.com
This will obviously only have any effect on the local machine.
127.0.0.1 mythirddomain.comwas correct. The reason my browser wasn't resolving mythirddomain.com correctly is because I hadn't restarted my browser.

how to change xampp htdocs directory in OSX?

I want to change XAMPP's htdocs directory. I followed the instructions to create a virtual host from this question:
Make XAMPP/Apache serve file outside of htdocs
this works fine on Windows 7, however when I try it on OSX, going to mysite.local just loads the xampp splash screen (mysite.local/xampp/index.html). I have restarted the web server. My virtual host declared in httpd-vhosts.conf is:
<VirtualHost *:80>
DocumentRoot Users/username/Documents/sitename.com
ServerName sitename.localhost
<Directory Users/username/Documents/sitename.com>
Order allow,deny
Allow from all
</Directory>
Open the following file in a text editor.
/Applications/XAMPP/xamppfiles/etc/httpd.conf
Search for "DocumentRoot", if the line below has a # in front of it than it's commented remove it and change the path between the quote
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
Now search for the line below and change the path between the quotes to your needs.
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
NOTICE: Paths similar to ~/ won't work use the absolute path.
I would like to expand this answer for 2022.
You will have to change 3 files if you want to keep web root in another directory. Let's say that you have installed XAMPP regularly, but your httpd directory is on another volume. Let's say in work/xampp/
Open /Applications/XAMPP/xamppfiles/apache2/conf/httpd.conf and change it to the following
Alias /bitnami/ "/Applications/XAMPP/xamppfiles/apache2/htdocs/"
Alias /bitnami "/Applications/XAMPP/xamppfiles/apache2/htdocs"
DocumentRoot "/Applications/XAMPP/xamppfiles/apache2/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
DocumentRoot "/Volumes/work/xampp"
<Directory "/Volumes/work/xampp">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
We have added
DocumentRoot "/Applications/XAMPP/xamppfiles/apache2/htdocs"
and the block
DocumentRoot "/Volumes/work/xampp"
<Directory "/Volumes/work/xampp">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Open file /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf and change it to the following
<VirtualHost *:80>
DocumentRoot "/Volumes/work/xampp"
</VirtualHost>
<VirtualHost yoursite.mac:80>
ServerName yoursite.mac
ServerAlias www.yoursite.mac
ServerAdmin webmaster#yoursite.mac
DocumentRoot "/Volumes/work/xampp/yoursite.mac/webroot"
ErrorLog "/Volumes/work/xampp/yoursite.mac/logs/oll.mac-error_log"
CustomLog "/Volumes/work/xampp/yoursite.mac/logs/oll.mac-access_log" common
<Directory "/Volumes/work/xampp">
Require all granted
</Directory>
</VirtualHost>
Open /etc/hosts as a sudo and add your new site to it
127.0.0.1 yoursite.mac
If you forward to a directory in your user root, then:
DocumentRoot "/Users/<your username here>/Sites"
<Directory "/Users/<your username here>/Sites">
Other than the answers mentioned above, I also had to change the line in XAMPP/xampfiles/etc/httpd.conf where it mentions username. the default was set to daemon and I changed it to my username; so there was no permission problem.
solved by editing httpd.conf
I have got this working. As per http://www.acwolf.com/blog/2009/February/xampp-virtual-hosts-mac, in OSX it is necessary to make two changes to httpd.conf, first, uncomment
#Include /Applications/xampp/etc/extra/httpd-vhosts.conf
and second, change the user from nobody to the username you use to log into OSX. You may also need to delete your browser's cache.

The 'official' way to deploy multiple Rail 3.1 Apps with Passenger

I'm currently trying to get a couple of small Rails apps running on a server, normally I've used Heroku but I decided to DIY it this time for practise, and everything that is suggested on the Internet doesn't work.
I've tried pretty much all of the resources I can find on both SO and the full Phusion guide, the closest I can come is "The page you were looking for doesn't exist." The app itself runs fine when I run it with script/rails server, initalizing a new rails app to a different sub_dir runs fine, but it'll only let me use index.html, nothing else. So it looks like some kind of routing issue, but when I tried the "scope do" it falls over on "scope".
What's the actual recommended and suggested way to have multiple rails sites on sub uris?
Apache2 Configuration File
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.cybershrike.co.uk/
DocumentRoot /web/rails
<Directory /web/rails>
Allow from all
</Directory>
RailsBaseURI /test
<Directory /web/rails/test>
Options -MultiViews
</Directory>
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.cybershrike.co.uk/
DocumentRoot /web/rails
<Directory /web/rails>
Allow from all
</Directory>
RailsBaseURI /kinu
RailsEnv development
SetEnv RAILS_RELATIVE_URL_ROOT "/kinu"
PassengerAppRoot /web/rails/kinu
<Directory /web/rails/kinu/public>
Options MultiViews Indexes FollowSymLinks
</Directory>
</VirtualHost>
Have you tried the proposed default passenger option?
RailsBaseURI /kinu
RailsEnv development
<Directory /web/rails/kinu/public>
Options -MultiViews
</Directory>
</VirtualHost>
Also you have to ensure, that file-permission allow the apache-server (ususally wwwuser) to access all files recursively including /web ?
And, just to cover all bases here: did you restart apache?

Resources