Remove web / app.php of reference. Symfony2 - symfony

All requests go through the file web / app.php (similar to index.php), such as a request to the main page - adwords-up.com/web/app.php, input - adwords-up.com /web/app.php/login. I want part of the web / app.php removed from the link. In the configuration .htaccess, redirect to the default web / app.php, so that a request for such was the main form - http://adwords-up.com/, and Page login - http://adwords-up.com/login.
There is my /etc/apache2/sites-available/adwords-up.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port t$
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName adwords-up
ServerAdmin webmaster#localhost
DocumentRoot /var/www/adwords-up/web
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

this might help you
<IfModule mod_rewrite.c>
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the app.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the startpage because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
</IfModule>
add this to your .htaccess and be sure to have rewriteEngine activated
also this is a common question with answers even on the symfon2 doc

You need to set up apache virtual host and put the correct document root and rewrite rules.
example:
<VirtualHost *:80>
ServerName adwords-up.com
DocumentRoot <path-to-your-codebase>/web
DirectoryIndex app.php
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
RewriteEngine on
RewriteOptions Inherit
RewriteRule ^/app.php/(.*) http://adwords-up.com/$1
RewriteRule ^/(.*) /app.php/$1 [QSA,L]
<Directory "<path-to-your-codebase>/web">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
Hope it helps

Related

Redirect Server Aliases to Server Name Over HTTPS on Apache

I have been looking around for an answer to my problem for a while and have read various other answers without coming across one that works for me.
The problem I am trying to solve involves redirecting access to a WordPress site installed on an Apache server. The WordPress site is one of many installed as part of a WordPress Network installation and the site is setup on the domain https://www.mysite1.co.uk.
It is also necessary to access the site using a number of server aliases, which are to be redirected to the root domain. I have created the additional domains as server aliases in the Apache configuration, and have set redirects to ensure that if one of the aliases is entered then it should be redirected to the root domain.
<VirtualHost *:80>
ServerName www.mysite1.co.uk
ServerAlias mysite1.co.uk www.mysite2.co.uk mysite2.co.uk
...
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)\.?$ [NC]
RewriteRule ^ https://www.mysite1.co.uk%{REQUEST_URI} [R=301,L]
</VirtualHost>
<VirtualHost *:443>
ServerName www.mysite1.co.uk
ServerAlias mysite1.co.uk www.mysite2.co.uk mysite2.co.uk
...
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)\.?$ [NC]
RewriteRule ^ https://www.mysite1.co.uk%{REQUEST_URI} [R=301,L]
SSLEngine On
SSLCertificateFile "certs/mysite1.co.uk.crt"
SSLCertificateKeyFile "certs/mysite1.co.uk.key"
</VirtualHost>
This configuration works whenever the user enters one of the aliases using http, they are redirected to https://www.mysite1.co.uk/. However, if they enter the aliases using https, instead of being redirected to https://www.mysite1.co.uk/, they are not being redirected at all.
Have I missed something in the configuration, or do I need to separate the https configuration and add the aliases into their own virtual host to do the redirect.
The sites are hosted on CentOS 7.9.2009 and running Apache 2.4.6.
If I got it correctly, you're trying to redirect every known domain reaching your apache to just one domain and when the connection comes as HTTP you want to redirect it to HTTPS.
To keep the configuration simple, I would create 3 different virtual hosts:
The first one will listen on http and include every domain you want to redirect (including the main one becuase it's listening on http). This virtualhost will redirect everything to the main domain over https:
<VirtualHost *:80>
ServerName main.site.com
ServerAlias mysite.example.com
ServerAlias another.site.com
Redirect permanent / https://main.site.com/
</VirtualHost>
The second one will listen on https port and includes all the domains but the main one and redirect it to your primary domain (it's like the previous one except it doesn't include the main domain)
<VirtualHost *:443>
ServerName mysite.example.com
ServerAlias another.site.com
Redirect permanent / https://main.site.com/
...
SSLEngine On
...
</VirtualHost>
In the end, the main one will just listen on https and will include only the main domain:
<VirtualHost *:443>
ServerName main.site.com
...
SSLEngine On
...
</VirtualHost>
This way, the only virtualhost requiring configuretiona (document root, locations, etc.) is the last one.

How can I change www.mysymfonypage.com/public to www.mysymfonypage.com?

When I locally open the url localhost:8000 then I see my main homepage.
I installed the apache pack (composer require symfony/apache-pack) and uploaded everything via ftp on my server.
This is the .htaccess file in my public folder:
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex index.php
# By default, Apache does not evaluate symbolic links if you did not enable this
# feature in your server configuration. Uncomment the following line if you
# install assets as symlinks or if you experience problems related to symlinks
# when compiling LESS/Sass/CoffeScript assets.
# Options FollowSymlinks
# Disabling MultiViews prevents unwanted negotiation, e.g. "/index" should not resolve
# to the front controller "/index.php" but be rewritten to "/index.php/index".
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the index.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/index.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# Rewrite all other queries to the front controller.
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 307 ^/$ /index.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
I open www.mysymfonypage.com and it redirects to the public folder, which is fine. But my URL is now www.mysymfonypage.com/public
How can I change this?
Really you should reconfigure your webserver to use /public as webroot - How do I change the root directory of an apache server?
Alternatively you could add
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,R=301]
after RewriteEngine On - BUT this will 301 redirect all your requests so that would likely cause issues / undesired behaviour somewhere along the line.

Subdomain always redirect to WWW (home page)

I want, when open subdomain to return existing Wordpress page ex. www.example.com/custom-wordpress-page.
Server OS is CentOS 6.6, while Web Server (httpd) is Apache 2.2.15.
It have installed and configured Wordpress with .htaccess files configured for it's mod_rewrite.
Root folder is /var/www/html.
.htaccess file is in /var/www/html/.htaccess :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
This configuration is working very well with one domain (ex. example.com). Today I wanted to add subdomain (ex. subdomain.example.com).
I tried multiple solutions including VirtualHosts with/without NameVirtualHost in httpd.conf file, also adding RewrriteCond&RewriteRule
under mod_rewrite in .htaccess file.
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin email-address-redacted
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
ServerAdmin email-address-redacted
ServerName subdomain.example.com
ServerAlias subdomain.example.com
Redirect permanent / http://example.com/custom-wordpress-page
</VirtualHost>
Also in first VirtualHost, I tried *.example.com instead off www.example.com.
In second one, I tried to make Reverse Proxy using ProxyPass and ProxyPassReverse.
Instead of using :*80 I tried using IP address of server and domain name.
Using .htaccess Rewrite rule with/without VirtualHosts gave no results.
subdomain.example.com always opens www.example.com instead of www.example.com/custom-wordpress-page.
Keep in mind - there is a lot of threads like this, but I tried many of them, including many tutorials but they aren't working alongside Wordpress.
Edit : Want to add that there are no wildcards in DNS records. There are NS records, one A record for example.com, one A record for subdomain.example.com and CNAME record for www that is poiting to example.com. There are NO *.
There was problem with hosting provider DNS records, configuration was correct, but I had to call provider to check records in their system and fix what is broken. After they done their job, it works correctly.

Wordpress “Post name” permalinks not working

I have a Wordpress website running on Lamp Server on Ubuntu Server 14.04.
I just tried to use the option for Post Name permalinks, and now my pages no longer load up.
I turned on the mod_rewrite function of the Apache server, restarted it, but it still doesn't work.
Also, here's my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Note that the content of /wordpress folder has been put directly inside /html
Let's say the name of my website is mywebsite.com.
How can I make it work?
EDIT: Here is my /etc/apache2/sites-available/000-default.conf file
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
I found a fix. So happy!
In short, the fix for me was to go into the WordPress admin dashboard, go to:
“Settings” > “Permalinks” > “Common settings”, and set the radio button to “Custom Structure”
, and paste into the text box:
/index.php/%year%/%monthnum%/%day%/%postname%/
, and click the Save button
have you enabled the use of .htaccess like described here ?
https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles
For those running apache 2.4 and not finding "default" look in /etc/apache2/apache2.conf and edit
Directory
AllowOverride All
Directory
Directory /var/www/>
AllowOverride All
Directory
edit .ht_access
insert this line in IfModule mod_rewrite.c
RewriteRule ^(.*)$ index.php?_REQUEST=$1 [L]
IT work for me.

symfony Oops! An Error Occurred The server returned a "404 Not Found" on production

Be patience I'm brand new at symfony framework
if I run:
php app/console server:run
it works fine
if I go to:
http://myproject.com/app_dev.php
it works fine
if I go to:
http://myproject.com
I got that error
my project.conf
<VirtualHost *:80>
ServerName myproject.com
ServerAlias www.myproject.com
DocumentRoot /home/whisher/public_html/myproject/web
<Directory /home/whisher/public_html/myproject/web>
# enable the .htaccess rewrites
AllowOverride All
Order allow,deny
Allow from All
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
Can you help me, please ?
.htaccess
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the app.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
Symfony 3 FYI: the command is now:
php bin/console debug:router --env=prod
Also you need to use the following to clear the cache after updating routing.yml:
php bin/console cache:clear --env PROD
Hope this helps some people.
Your configuration seems to be ok. I think that is not a problem.
Try to check application routing by:
php app/console router:debug --env=prod
If the result is empty that you should check if there is any routes defined in:
app/config/routing.yml
and move product routing from routing_dev.yml to config file listed above.
Good Luck!
In my case it was a file ownership and permissions problem with the "cache" "logs" and "sessions" directories when installing symfony in a user public_html directory. I solved it with the following commands
$ chmod g+w myproject/var
$ rm –rf myproject/var/cache
$ rm –rf myproject/var/logs
$ rm –rf myproject/var/sessions
$ ls -ld myproject/var
drwxrwx--- 5 whisher www-data 4096 Feb 16 16:35 var/
Now symfony was able to create the directories with the correct permissions and ownership.
Try to clean prod cache, in app/cache/prod delete all files. It work for me.
php app/console cache:clear --env=prod

Resources