How go to home page correctly? - apache

I enable mod_rewrite but when I go to home page the browser try download something. When I go to app_dev.php the browser show error:
The requested URL /app_dev.php/ was not found on this server.
My locale host was configurated to web directory.
the output of 'app/console router:debug _welcome' is:
[router] Route "_welcome"
Name _welcome
Path /
Host ANY
Scheme ANY
Method ANY
Class Symfony\Component\Routing\Route
Defaults _controller: Acme\DemoBundle\Controller\WelcomeController::indexAction
Requirements NO CUSTOM
Options compiler_class: Symfony\Component\Routing\RouteCompiler
Path-Regex #^/$#s
my httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin myemail#email.com
DocumentRoot "/var/www/symfony/hz.dev/web"
ServerName hz.dev
ServerAlias www.hz.dev
ErrorLog "/var/log/apache2/hz.dev-error_log"
CustomLog "/var/log/apache2/hz.dev-access_log" common
</VirtualHost>
My web/.htaccsess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule .? %{ENV:BASE}app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>

Try this .htaccess instead. It's very simple, I use it during development.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>
You should then be able to access Symfony at http://example.com/ without app_dev.php in the URL

Related

Apache vhost double slash on redirects

I was trying to force the FQDN and HTTPS via Apache Vhost redirects in a Laravel application behind a reverse Proxy. My problem now is that the user sometimes gets redirected to a URL with double slash e.g. https://exampledomain.xy//test instead of https://exampledomain.xy/test and I'm not sure why.
Here is my apache vhost configuration:
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/public
<Directory /var/www/html>
AllowOverride All
</Directory>
ErrorLog /dev/stderr
TransferLog /dev/stdout
RewriteEngine on
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTP_HOST} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
RewriteCond %{REMOTE_ADDR} !=::1
RewriteRule (.*) https://exampledomain.xy/$1 [L,R=301]
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/var/www/html/public"
ServerName exampledomain.xy
</VirtualHost>
And my .htaccess file (default .htacces file that comes with Laravel)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Okay looks like I fixed the issue. I changed the following in my config:
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://stk-support.ukl.uni-freiburg.de$1 [R=301,L]
The extra slash in the rewrite rule was causing the issue and I also added a HTTPS rewrite condition.

htaccess redirect not working on co.uk domain

Here is my apache configuration:
DocumentRoot "/www/public"
<Directory "/www/public">
Options Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
NameVirtualHost *:80
<VirtualHost *:80>
ServerAlias www.domain.com domain.com
DocumentRoot /www/public
ServerName www.domain.com
</VirtualHost>
<VirtualHost *:80>
ServerAlias www.domain.co.uk domain.co.uk
DocumentRoot /www/public
ServerName www.domain.co.uk
</VirtualHost>
Here is what my htaccess looks like:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} !=/server-status
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php [NC,L,QSA]
</IfModule>
If I access www.domain.com, domain.com, or www.domain.co.uk everything works fine. However, when I access domain.co.uk, it doesn't redirect properly to www.domain.co.uk. It seems like the co.uk requests are not reading my htaccess.
Solution was to change the HTACCESS from:
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
To
RewriteCond %{HTTP_HOST} (^[^.]+\.[^.]+$|^[^.]+\.co\.uk$)
That is due to the regex used in www adding rule. Change that to:
RewriteCond %{HTTP_HOST} ^[^.]+\.(?:[^.]+|co\.uk)$ [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Make sure to clear your browser cache before testing this change.

Delegate specific URL request to specific Directory

Taking forward from my last question i.e. Mapping domains to Tomcat Apps. Now I want that if a particular request came i.e.
http://www.app1.com/blog
then this would be redirected to a specific folder on my server. I did tried below code
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/blog/ /path_to_my_site/app1_com/blog/ [L]
but that has gone horribly wrong as that has become redirect loop, so I removed it immediately.
Note: My site www.app1.com is hosting java application and www.app1.com/blog would be php application blog.
Update 1
for the sake of clarity below is my virtual host configuration
<virtualhost *:80>
ServerName app1.com
ServerAlias app1.com www.app1.com
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^blog(/.*)?$ /path_to_my_site/blog/ [L,NC]
ProxyPass / ajp://127.0.0.1:8009/app1/
ProxyPassReverse / ajp://127.0.0.1:8009/app1/
</virtualhost>
Update 2
contents of .htaccess in blog folder is
# Pretty Permalinks
RewriteRule ^(images)($|/) - [L]
RewriteCond %{REQUEST_URI} !^action=logout [NC]
RewriteCond %{REQUEST_URI} !^action=login [NC]
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /blog/
RewriteCond %{REQUEST_URI} !index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?filename=$1 [NC,QSA,L]
You can use:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^blog(/.*)?$ /path_to_my_site/app1_com/blog/ [L,NC]
/path_to_my_site/app1_com/blog/ should be a valid path under DocumentRoot.
Change your ProxyPass line to this:
ProxyPass /blog !
ProxyPassMatch ^/(?!blog).*$ ajp://127.0.0.1:8009/app1/
ProxyPassReverse / ajp://127.0.0.1:8009/app1/

http to http redirect virtual host in apache

Hi im configuring a server in CentOS 6.5 with apache 2.4 and PHP 5.5
I install an SSL certificate and all go fine.
in another server i did the http to https redirect on htaccess file.
i meke test with that in my new server and didnt work, here are my configuration:
My .htaccess:
<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
RewriteCond %{REQUEST_URI} !/phpmyadmin/.*
RewriteCond %{REQUEST_URI} !/phpMyAdmin/.*
RewriteRule ^ index.php [L]
</IfModule>
My virtual host file:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName subdomain.domain.com
ServerAlias www.subdomain.domain.com
DocumentRoot /var/www/laravel-project-namel/public
<Directory /var/www/laravel-project-namel/public>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
NameVirtualHost *:443
<VirtualHost *:443>
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile /etc/pki/tls/certs/cert-valido_clientes_databyte_cl.crt
SSLCertificateKeyFile /etc/pki/tls/certs/cert-valido-private.key
SSLCertificateChainFile /etc/pki/tls/certs/cert-valido_clientes_databyte_cl.pem
ServerName subdomain.domain.com
ServerAlias www.subdomain.domain.com
DocumentRoot /var/www/laravel-project-namel/public
<Directory /var/www/laravel-project-namel/public>
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
i replace the domain and the folder to generic names, but all other are true.
(sorry about my english)
i did search and test every solution i found, but my site refuse to redirect.
Problem is you're not capturing the URI in patter and using $1, %1 as back-reference.
Try this rule in your root .htaccess as very first rule:
RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,L,NE]

RewriteRule to cause subdomain to load another DocumentRoot?

Apache (mostly) noob here... could sure use a little help with what I am trying to do with a RewriteRule in .htaccess:
...to causes URLs using our sharpedge. subdomain to auto-load from the Internet_IE directory - one level deeper than the site root.
I have this in httpd.conf:
[snip]
NameVirtualHost 11.22.33.44
<VirtualHost 11.22.33.44>
Options All +ExecCGI
ServerAdmin hostmaster#ourhost.com
DocumentRoot /var/www/html/ourdomain.com
ServerName ourdomain.com
ServerAlias www.ourdomain.com
DirectoryIndex index.htm index.html index.dna
#---------------------------------
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
#---------------------------------
</VirtualHost>
<VirtualHost 11.22.33.44>
Options All +ExecCGI
ServerAdmin hostmaster#ourhost.com
DocumentRoot /var/www/html/ourdomain.com
ServerName sharpedge.ourdomain.com
DirectoryIndex index.htm index.html index.dna
#---------------------------------
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
#---------------------------------
</VirtualHost>
[snip]
...and this in .htaccess (in the site root, here: /var/www/html/ourdomain.com/)
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sharpedge\.ourdomain\.com$
# years ago this next line was used here, but in httpd.conf: (I don't know what it was supposed to do)
# RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^sharpedge\.ourdomain\.com(.*) /var/www/html/ourdomain.com/Internet_IE/$1 [L]
</IfModule>
..but nothing happens from the RewriteRule; it is as if the RewriteRule was not there.
I'd much appreciate any suggestions.
Edits:
I would just change the DocumentRoot to the directory I actually want to serve, but I need to be able to call (include) files from within files in that directory with a prefixing / in the include path, where those files are located in the site root. Those files are also similarly called from other files that are in the site root.
You don't want to put any part of your host in the RewriteRule, but you got the HTTP_HOST right, try:
RewriteCond %{HTTP_HOST} ^sharpedge\.ourdomain\.com$ [NC]
# to prevent looping
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Internet_IE/$1 [L]
Try changing the !-f and !-d checks:
RewriteCond %{HTTP_HOST} ^sharpedge\.ourdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/Internet_IE/
RewriteRule ^(.*)$ /Internet_IE/$1 [L]