Below you will find my current vHost entry that I am using for a site that I currently have under development. This vHost entry works fine when I have it on my local machine, but when I push my code to my staging server that is running this same vHost record I receive a 500 Internal Server error.
The machine I'm running this vHost on is running Apache 2.2.9 (Debian).
<VirtualHost 206.217.196.61:80>
SuExecUserGroup 13labs 13labs
ServerAdmin aellis#1three.com
ServerName admin.13labs.net
ServerAlias admin.13labs.net
DirectoryIndex index.php
DocumentRoot /var/www/13labs.net/html/admin/
ErrorLog /var/www/13labs.net/logs/error.log
# Hide .svn Directories
<DirectoryMatch "\.svn">
Order deny,allow
deny from all
</DirectoryMatch>
# FastCGI
Alias /fcgi-bin/ /var/www/13labs.net/fcgi-bin/
AddHandler php-fastcgi .php
AddType application/x-httpd-php .php
Action php-fastcgi /fcgi-bin/admin-php.fcgi
<Directory /var/www/13labs.net/fcgi-bin/>
SetHandler fcgid-script
AllowOverride None
Options -Indexes +ExecCGI -FollowSymlinks -SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/13labs.net/html/admin/>
AllowOverride None
Options -Indexes -FollowSymlinks -SymLinksIfOwnerMatch
FileETag All
</Directory>
# Rewrite Logic
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !\.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^/(.+)$ /index.php/$1 [PT,QSA,L]
Thanks for any help that you can provide.
Best regards,
Andrew
After many trial and errors I have found that the working RewriteRule needs to be the following:
RewriteRule ^.*$ /index.php$1 [PT,QSA,L]
Then in PHP I need to be using $_SERVER['REQUEST_URI'] instead of $_SERVER['PATH_INFO'] to make sure my PHP script see the passed in URI.
Related
I made a virtual host on the remote server and it works, but I would like to include the name of the app in the url address...
example: 10.10.20.30 - work, the homepage of the app opens, but 10.10.20.30/e-lab don't work...
These are my files for a virtual host:
httpd-vhost.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/e-lab/public"
ServerName e-lab.test
<Directory "C:/xampp/htdocs/e-lab/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
hosts
127.0.0.1 localhost
127.0.0.1 e-lab.test
and htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Thanks! ;)
I solved the problem ... In the localhost links works ok, example: <a href=/login> , but over the remote server this slash line deletes the folder name (name of aplication), so i put it all links {{url('something')}} and now it's ok ... thanks anyway ;) –
I'm trying to install Laravel on Wamp server and I'm getting this error:
{"status":"Not Found","error":true,"error_code":"missing_route","message":"Route not found.","data":[]}
Been searching for a while now and can't figure out what it is. I checked and triple checked if I added corectly my project in hosts file, if virtual host is set properly, also if rewrite module is activated and if .htaccess file in the public folder is as it should.
Hosts File:
127.0.0.1 app.my-site.com
Vhosts
<VirtualHost *:80>
ServerAdmin webmaster#my-site.com
DocumentRoot "C:/wamp/www/my-site/public"
ServerName app.my-site.com
<Directory "C:/wamp/www/my-site/public">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "logs/my-site-error.log"
CustomLog "logs/my-site-access.log" common
</VirtualHost>
.htaccess in public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Can anybody suggest what could be wrong?
I have a frontend app at /var/www/html/app and the API for that app is at /var/www/html/api. There is a virtual host set up for /var/www/html/app, with the name example.com. Now, I want it so what when a user visits example.com/api, it will redirect all requests to /var/www/html/api.
Example:
User enters http://example.com/api/some/call into their browser - instead of the server looking for /var/www/html/app/api/some/call, it will look for /var/www/html/api/some/call.
What is the best way to get this done? I tried using symbolic links which works for just /api, but not for variable routes after /api. I am thinking I can get it working with mod rewrite, but I am not that familiar with it.
UPDATE
Here is the config for example.com in /etc/apache2/sites-available:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/app
ServerName example.com
ServerAlias www.example.com
<Directory /var/www/html/app>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Here in the .htaccess file in /var/www/html/app (and the same one at /var/www/html/api):
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I'm very new to apache. I read and read docs, turn all conf files I found, but ...
While I'm root on the webserver, I read that in order to optimize apache2, it is not a good idea to use .htaccess files (http://httpd.apache.org/docs/current/howto/htaccess.html).
OK, I read a lot of howtos about url_rewriting and htacess. I tried this code into my www.site.com virtualhost file :
<VirtualHost *:80>
ServerName site.com
ServerAlias www.site.com
ServerAdmin webmaster#site.com
DocumentRoot /var/www/www.site.com
RewriteEngine On
<directory />
RewriteBase /var/www/www.site.com/
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Please note that RewriteBase has been tested with DocumentRoot value and '/', and that all the RewriteCond come form std_htaccess of latest Joomla! source code.
Apache2 launches well, the site is viewed online with no error, but the rewrite is not working as joomla SEF is not working :(
I'm totaly lost ... again ... and I need your help guys !
Ok, the correct way is
<directory /var/www/www.site.com/>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
Options FollowSymLinks
AllowOverride None
</Directory>
I am using apache2 + tomcat on ubuntu 10.4. I am running on tomcat server that has webapps listening on 8080
"http://internal:8080/dir/name-privatewebapp/"
"http://internal:8080/dir/name-publicwebapp/"
External facing Apache server is proxying requests for the domain.
I would like to remap "subdomain" to "domain.com/subdomain" , so any other requests would be proxied to the appropriate path / webapp
web.john-doe.domain.com ---> www.domain.com/web/john-doe
http://www.john-doe.com ---> www.domain.com/web/john-doe
http://www.foo-bar.com ---> www.domain.com/web/foo-bar
I couldnt make it work with mod_rewrite alone. I have been looking into
mod_proxy, mod_proxy_ajp, and mod_rewrite
I would like the server to
Grab the subdomain from the domain
Make sure the subdomain is not www, w or ww
Check if the directory actually exists on "www.domain.com" before rewrite
if the directory doesnt exist it stays as wild domain
Finally, if the directory exist the actual rewrite
I checked several links and studied tutorials on http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html
It is without success.
I followed this
illumin-it.servehttp.com/wordpress/2012/01/redirecting-to-as-using-apache/
with a bit of success.
However, I would like to the server to do it on the fly through rewrites and proxies without editing the vhost for every subdomain.
here is my updated vhost file
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName www.domain.com
ServerAlias www.domain.com domain.com *.domain.com
RedirectPermanent / http://www.domain.com
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
# Prevent looping this rule
# RewriteCond %{ENV:REDIRECT_STATUS} !200
# RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
# RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9.-]+).domain.com$ [NC]
# RewriteRule (.*) /%2/$1 [L]
# change the "." in the path to "/"
# RewriteRule ^(.*)\.(.*)/(.*)$ /$1/$2/$3 [L]
#redirect domain.com to www.domain.com
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteRule ^ http://www.domain.com%{REQUEST_URI} [R=301,NC]
</IfModule>
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# ErrorLog /var/log/apache2/webapp_error.log
# LogLevel warn
# CustomLog /var/log/apache2/webapp_access.log combined
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
# ProxyPass /user/ http://localhost:8080/user/privatewebapp/
# ProxyPassReverse /user/ http://localhost:8080/user/privatewebapp/
#
# ProxyPass /publicweb/ http://localhost:8080/dir/publicwebapp/
# ProxyPassReverse /publicweb/ http://localhost:8080/dir/publicwebapp/
#
# ProxyPass / http://localhost:8080/dir/publicwebapp/
# ProxyPassReverse / http://localhost:8080/dir/publicwebapp/
ServerName www.domain2.com
ProxyRequests Off
ProxyPreserveHost On
RewriteEngine On
RewriteCond %{HTTP_HOST} ^dir/publicwebapp$ [NC]
RewriteRule ^(.*)$ http://www.domain2.com/$1 [R=301,L]
<Location / >
Order deny,allow
Allow from all
RedirectMatch ^/$ /dir/publicwebapp/
ProxyPass ajp://localhost:8009/
ProxyPassReverse ajp://localhost:8009/
</Location>
</VirtualHost>
I also tried...
http://httpd.apache.org/docs/2.0/rewrite/rewrite_guide.html
assuming www.username.host.com/anypath internally maps to www.host.com/home/username/anypath
As the site's applications created with Java servers, I believe mod_rewrite alone doesnt work.
Virtual User Hosts
RewriteCond %{HTTP_HOST} ^www\.[^.]+\.host\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^www\.([^.]+)\.host\.com(.*) /home/$1$2
Your first set of rules:
#redirect domain.com to www.domain.com
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule .+ http://www.domain.com%{REQUEST_URI} [R=301,NC]
Is superceding any subdomain you have if you don't have an empty request. The second set of rules comes close to what you want. But they loop and they don't turn multiple subdomain entries into directory paths, so try putting this set of rules first:
# Prevent looping this rule
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9.-]+).domain.com$ [NC]
RewriteRule (.*) /%2/$1 [L]
# change the "." in the path to "/"
RewriteRule ^(.*)\.(.*)/(.*)$ /$1/$2/$3 [L]
Then change your "non-www to www" rule to this (and place after the above rules):
#redirect domain.com to www.domain.com
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteRule ^ http://www.domain.com%{REQUEST_URI} [R=301,NC]
In similar cases I usualy put somethin like this to .htaccess in webroot (/var/www/.htaccess):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} subdomain1.domain.com
RewriteCond %{REQUEST_URI} !^/subdomain1
RewriteRule ^(.*)$ one/$1 [L]
RewriteCond %{HTTP_HOST} subdomain2.domain.com
RewriteCond %{REQUEST_URI} !^/subdomain2
RewriteRule ^(.*)$ two/$1 [L]
RewriteRule ^$ / [L]
RewriteRule (.*) /$1 [L]
</IfModule>
so I have
subdomain1.servername.com -> /var/www/subdomain1
subdomain2.servername.com -> /var/www/subdomain2
servername.com -> /var/www
Maybe this will help you?