Symfony htaccess to subfolder - .htaccess

I have some domain e.g domain.com
In main folder I have a phpBB forum.
I have my Somfony 3.4 app in subfolder named e.g. symfonyfolder.
I have problem with my .htaccess file.
In main folder I have normal phpBB .htaccess and I added:
RewriteRule symfonyfolder/(.*) symfonyfolder/web/$1 [L]
In symfonyfolder I do not have .htaccess file. In symfonyfolder/web I have such .htaccess file:
DirectoryIndex app.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^ %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
But then I get uri like that:
domain.com/symfonyfolder/web//web//web//web//web//web//web//web//web//web//web//web//web//web//web//web//web//web//web//
What have I done wrong?
//Ubuntu 16.04, Apache 2.4

Related

How to use URL Rewriting on a htaccess file

How can I rewrite the URL so instead of looking like this:
website.com/index.php/acars
it looks like this:
website.com/index.php?p=acars
and maybe like this:
website.com/acars
here is an example i use in a symfony2 project (i think it's the default symfony htaccess):
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /index.php/
</IfModule>
</IfModule>
so every request like website.com/acars will be handled like website.com/index.php/acars

A bad use of RedirectPermanent

I try actually to change my url => www.mysite.com to www.mysite.com/fr/ and i have to use my .htaccess for that.
So i changed my .htaccess from my root like that:
SetEnv SHORT_OPEN_TAGS 0
SetEnv REGISTER_GLOBALS 0
SetEnv MAGIC_QUOTES 0
SetEnv SESSION_AUTOSTART 0
SetEnv ZEND_OPTIMIZER 1
SetEnv PHP_VER 5_3
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [QSA,L]
RedirectPermanent / http://www.chat.com/fr/
</IfModule>
and i have my /web/.htaccess like that:
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
and when i try to upload my site, i have this url : www.mysite.com/fr/fr/fr/fr/... and an error. Someone can help me ? :(
Your rules will indeed cause a redirect loop. Try this in root .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/?$ /fr/ [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [L]
</IfModule>
Make sure to test this after clearing your browser cache.

How to make other subdirectory work with cakephp in root?

I have this path in my hosting server with domain http://www.example.com/ and it's running cakephp in the directory home. but now I want my another_project_name appear in browser with http://www.example.com/another_project_name/.
This is my structure :
/www
.htaccess
home/
.htaccess
webroot/
.htaccess
lib/
another_project_name/
This is my /www/.htaccess :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ home/webroot/ [L]
RewriteRule (.*) home/webroot/$1 [L]
</IfModule>
How to configure .htaccess file in /www/.htaccess to make my another_project_name work ?
Try this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule (another_project_name/.*) $1 [L] # adjust the regex to what you want.
RewriteRule (another_project_name.*) $1 [L] # adjust the regex to what you want.
RewriteRule ^$ home/webroot/ [L]
RewriteRule (.*) home/webroot/$1 [L]
</IfModule>
.htaccess file should be like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/?(another_project_name)/(.*)$
RewriteRule ^.*$ - [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
For multiple directories
RewriteCond %{REQUEST_URI} ^/?(another_project_name1 | another_project_name2 | another_project_name3 )/(.*)$

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>

subdomain rewrite rule lithium framework

I plan to have this as a URL:
https://SubDomain.domain.com/<locale>/Controller/action/param1/param2/?query=param3
in Lithium Framework (li3.me)
What is the purpose of the htaccess files in Lithium?
It should redirect me through .htaccess as:
https://domain.com/<locale>/Conttroller/action/param1/param2/?query=param3&subdomain=SubDomain
In Lithium framework there are 3 .htaccess files:
1. /.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
2. /app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
3. /app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# Uncomment the line below, to enable HTTP authentication running PHP as a CGI.
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !favicon.ico$
RewriteRule ^ index.php [QSA,L]
</IfModule>
I tried to edit the root /.htaccess file to get the subdomain name as a parameter without any success.
Pass subdomain as parameter
Dynamic subdomain rewrite htaccess
.htaccess Wildcard Subdomains
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !mydomain\.com$ [NC]
RewriteRule ^(.*)$ app/webroot/$1?subdomain=%1 [L]
Do I have to rewrite rules in all 3 .htaccess files? If so, what are the changes needed?
Thanks!

Resources