Symfony 5.2 - apache configuration doesn't work - .htaccess

I've created a Syfmony 5.2 project and on my local I've used symfony serve -d. So, when I've put the project live, I need an .htaccess file. Well, it looks like below:
DirectoryIndex index.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 307 ^/$ /index.php/
</IfModule>
</IfModule>
The result?
The page isn’t redirecting properly
Please, can someone tell me what I've missed?

please have a look here:
https://symfony.com/doc/current/setup/web_server_configuration.html
I am not very familiar with Apache, I usually use NGINX but on first look, it looks like you need to define a document root to /var/www/project/public.
I hope you can move forward with this information.

Related

Page redirection with .htaccess

I need to make a target, when the user access, https://www.dominio.com.br/portal/anything be directed to https://www.domain.com.br/blog
Is it possible to do this with .htaccess?
Here is the code I have:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule .* / [R=200,L]
RewriteRule ^portal/([a-z0-9\-]+)/$ ^blog/ [QSA]
</ifModule>
Note: Inside the portal folder, I already have an index.php pointing to blog. This .htaccess would go inside this folder.
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^portal/(.*) blog/$1 [L,QSA]
</ifModule>

Need to remove pages full link path from the web link

I need to remove pages full link path from the web link: http://web.example.com/web/#bwc/index.php to be http://web.example.com/
What modifications has to be done?
Try this:
<IfModule test_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ web/$1 [L]
</IfModule>
I hope it will help..
If you use Apache, https://gist.github.com/wataruoguchi/649963c3ee18640e0105 will be the answer.
ErrorDocument 503 /maintenance.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/maintenance.html
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
RewriteRule ^.*$ - [R=503,L]
</IfModule>
You can simply rewrite maintain.html to index.html

1and1 subdirectory cakePHP installation issue

I am deploying my app on a live server hosted on 1and1.co.uk.
I am trying to make it work since 8 and getting crazy, trying with a fresh version downloaded from the cakePHP website.
Here is my configuration.
A subdomain pointing to a directory :
subdomain.mydomain.com => /subdirectory
So I think the first question is, on the view of my app, is that a subdirectory ?
I don't think so but I am not sure.
I tried hundreds of .htaccess configurations, nothing works, I get a 500 error or the following message:
Parse error: syntax error, unexpected '=', expecting '(' in /homepages/41/d201409564/htdocs/hire/lib/Cake/bootstrap.php on line 173
I thought that topic would fix my problem, but still not working.
Thanks for your help
Could fix it finally thanks to : http://www.grafikart.fr/forum/topic/2351
Here is the solution, the trick is probably to enforce the PHP5, even if it's activated on your server (which is my case)
/.htaccess
AddType x-mapp-php5 .php
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
/app/.htaccess
AddType x-mapp-php5 .php
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/app/webroot/.htaccess
AddType x-mapp-php5 .php
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
If someone struggles about this with CakePHP 4.xx, this is how i got it running at IONOS (former 1and1). CakePHP is installed in a Subdirectory:
(Maindirectory)
Subdirectory (CakePHP)
/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
#the next two lines are only for forwarding to https
RewriteCond %{SERVER_Port} !=443
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
# end of forwarding
RewriteBase /
RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
webroot/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

How to remove /web using .htaccess in Symfony2?

I have deployed a Symfony application to my production server. Now I need to remove /web from the domain name, and I have searched for different solutions for this. For example I tried this, but it only resulted in a 500 error. I have read the answers of many similar questions, but I can´t find a solution that works. Could anyone give me a clue?
This is my htaccess-file:
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.se$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.se$
RewriteCond %{REQUEST_URI} !folder/
RewriteRule (.*) /web/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
This is what works for me
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>

cake .htaccess rewrite almost working

I'm having a problem with rewrite rules in my cake 2.2.0 app.
Mod_rewrite seems to be working as going here:
myapp.com/listings works
But links generated by cake construct this type of URL, which also work but are not being rewritten:
myapp.com/app/webroot/index.php/listings
I've tried a lot of posted options but nothing seems to work?
My apache config is set up as follows:
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
All .htaccess files are standard from the cake install?
Webroot .htacess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
App .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
root .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Should I be looking at anything else?
This is something you should be able to fix in cakephp when you generate your links. The htaccess files that you have won't change the links in your page content.
If for whatever reason, you can't do this in cakephp, then you can add this to your Webroot htaccess, right below the RewriteEngine On line:
RewriteCond %{THE_REQUEST} \ /app/webroot/index.php/([^\ ]+)
RewriteRule ^ /%1 [L,R=301]
and that will redirect the browser to the shorter URL.
In case any one else looks at this, my problem was that this line in /app/Config/core.php was uncommented:
Configure::write('App.baseUrl', env('SCRIPT_NAME'));
Commenting it out removed the abs URL /app/webroot/index.php/ from my URLs.
Happy coding.

Resources