I'm working on my first symfony 4 project and i would like to upload it on my online server. My goal is to have it online on my domain to test it before a preview with my client.
I tried to put my files on the www folder (by ftp) and add a .htaccess in the main repository with :
<IfModule mod_rewrite.c>RewriteEngine On
# remove "www" from URI
RewriteCond %{HTTP_HOST} ^devfuzz\.(.+) [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
# force HTTPS
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# use public as starting point
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]</IfModule>
And i added a .htaccess in public with :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
I tried so many thing found on many forum but i have always the same with when i try to go on my website :
website view
How can i change this view to have a normal navigation like i had with :
php bin/console server:run in local
Try to change your code with this one :
# remove "www" from URI
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
You don't need to remove the www in this part of code, this code will do it for you so do NOT change it :)
Related
In the webroot of my local server, I try to install Bedrock in it self directory :
|- htdocs
|- bedrock
|- web
With the .htaccess file I wrote, I can access the web directory and so launch my application :
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
RewriteCond %{HTTP_HOST} ^(www.)?example.local$
RewriteCond %{REQUEST_URI} !^/bedrock/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /bedrock/web/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.local$
RewriteRule ^(/)?$ bedrock/web/index.php [L]
However I would like to avoid accessing to bedrock directory with the url : example.local/bedrock.
Can I do this with rewrite module from Apache or do I have to add a .htaccess with deny from all in the bedrock directory ?
You can block direct access to the /bedrock subdirectory, but still allow requests be internally rewritten to that directory, by adding the following before your existing rules:
# Block "direct" access to the "/bedrock" subdirectory
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^bedrock($|/) - [F]
The above will return a "403 Forbidden" if /bedrock or /bedrock/<anything> is requested directly by the client.
By checking that the REDIRECT_STATUS environment variable is empty we can make sure the rule is only applied to direct requests (and not rewritten requests - later in the file).
The REDIRECT_STATUS env is empty on the initial request, but set to 200 (as in 200 OK status) after the first successful rewrite.
...or do I have to add a .htaccess with deny from all in the bedrock directory ?
That would block all requests, including your internal rewrites.
Aside:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
RewriteCond %{HTTP_HOST} ^(www.)?example.local$
RewriteCond %{REQUEST_URI} !^/bedrock/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /bedrock/web/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.local$
RewriteRule ^(/)?$ bedrock/web/index.php [L]
You should include the L flag on the first 2 rules. You've only included the L flag on the last rule (where it isn't strictly required).
You don't need the capturing group in the last rule. ^/?$ (or even ^$ in .htaccess) would suffice.
Problem:
My web hosting provider (apache) supports having multiple domains under one account, theese domains cointain wordpress installations and are managed via ftp client in a path:
www/domains/domain1.tld
www/domains/domain2.tld
When I open https://domain2.tld everything works as intended.
Anyways.. if I dont specify the 'https://' then it gets redirected to https://domain1.tld
What I have:
in www/domains I have this .htaccess file
RewriteEngine On
# domains
RewriteCond %{REQUEST_URI} !^domains/
RewriteCond %{REQUEST_URI} !^/domains/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$
RewriteCond %{DOCUMENT_ROOT}/domains/%2 -d
RewriteRule (.*) domains/%2/$1 [DPI]
# subdomains
RewriteCond %{REQUEST_URI} !^subdom/
RewriteCond %{REQUEST_URI} !^/subdom/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.([^\.]*)\.([^\.]*)$
RewriteCond %{DOCUMENT_ROOT}/subdom/%2 -d
RewriteRule (.*) subdom/%2/$1 [DPI]
# domains proper redirection when / is missing
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^domains/[^/]+/(.+[^/])$ /$1/ [R]
# subdomains proper redirection when / is missing
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^subdom/[^/]+/(.+[^/])$ /$1/ [R]
Then in each WP installation i have the wordpress .htacces file
# BEGIN WordPress
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
I did check database and wp-config, none of them contains links to
https://domain1.ltd
Both domains use Lets Encrypt certificate
I did search domain2.ltd localy with notepad++ for domain1.ltd occurences, found none, disabling all plugins didnt help either
Forcing https redirection didnt work either with:
RewriteCond %{HTTP_HOST} ^domain2\.tld [NC]
RewriteRule (.*) https://www.domain2.tld/$1 [R=301,QSA,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.domain2.tld/$1 [R=301,L]
To be honest i ran out of ideas what to do next. Anyone knows how to trubleshoot this? My guess is there is something wrong with the www/domains .htaccess file, or the web host.
Thank you guys!
In the end it was a wrong placement of the main htaccess file, which should be in www/ dricetory, not in www/domains
Anyways thank you for your time guys! :)
On my root directory of the domain example.com i've installed
a wordpress cms like this example.com/frontend/
Then i followed the WP guide lines to load the frontend directory directly by calling the main domain.
On the root path i've the main app that is accesible only by calling a direct URL (ex. domain.com/login.php ) because if i call domain.com/login/ it's going to look for a wordpress page domain.com/frontend/login/ that doesn't exist.
I would like to ask you how to adjust my htaccess file to solve this work araound.
Thank you.
I think installtion inside sub folder. please review link https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/my_subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir/index.php [L]
</IfModule>
I have a vbulletin with vbseo installed and the .htaccess code is
# Comment the following line (add '#' at the beginning)
# to disable mod_rewrite functions.
# Please note: you still need to disable the hack in
# the vBSEO control panel to stop url rewrites.
RewriteEngine On
# Some servers require the Rewritebase directive to be
# enabled (remove '#' at the beginning to activate)
# Please note: when enabled, you must include the path
# to your root vB folder (i.e. RewriteBase /forums/)
#RewriteBase /
#RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
#RewriteRule (.*) http://www.yourdomain.com/forums/$1 [L,R=301]
RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]
RewriteCond %{REQUEST_URI} !(admincp/|modcp/|cron|vbseo_sitemap|api\.php)
RewriteRule ^((archive/)?(.*\.php(/.*)?))$ vbseo.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !/(admincp|modcp|clientscript|cpstyles|images)/
RewriteRule ^(.+)$ vbseo.php [L,QSA]
the sub-domains have wordpress on it for example : games.domain.com not working it gives me Internal Server Error
so how to resolve this issue? and get's the domain and sub-domains work ?
I solve the problem by adding .htaccess file into games folder with the following code only
RewriteEngine Off
We have a site that runs on Symfony and that was developed by people much more competent that myself. I am however quite competent in WordPress and will be installing a blog on a the site.
Currently, the root of the site runs on Symfony but I would like for WordPress to take over without having to touch the Symphony core. Essentially, I would like to install WordPress in a sub directory of the www directory, say www/wordpress/ and have htaccess point to that directory as the root of my domain. BUT, there is one function of my Symfony installation I would like to still have access to, lets call it myfeature. When I go to mydomain.com/myfeature/ I would like for htaccess to point to mydomain.com/index.php/myfeature which is run by Symphony.
Here's what my current .htaccess file looks like.
<IfModule mod_rewrite.c>
RewriteEngine On
# we skip all files with .something
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteCond %{REQUEST_URI} !\.php
#RewriteCond %{REQUEST_URI} !\.php
RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ /index.html [QSA]
RewriteRule ^([^.]+)$ /$1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ /index.php [QSA,L]
# hidden frontoffice controller
RewriteRule ^index\.php/(.*)$ /index.php [QSA,L]
# fo controllers
RewriteRule ^frontend\.php/(.*)$ /frontend.php [QSA,L]
RewriteRule ^frontend_dev\.php/(.*)$ /frontend_dev.php [QSA,L]
</IfModule>
Thank You
I integrated a wordpress blog with my symfony site using the following.
//Added to the autoload.php
require('../vendor/wordpress/wp-blog-header.php');
I installe the blog into the main web folder and the .htaccess was set as follows,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/blog -------Add this condition to by pass the rewrite rules
RewriteRule ^(.*)$ app.php [QSA,L]
This allows all of the other routes to be accessed as normal but the blog routes are left untouched and passed directly to wordpress. To pull things from the wordpress database i was able to call the wordpress methods in my symfony controllers and pass it to my twig template.
$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
return array('posts'=>$posts);
I am not sure if this is exactly what you are asking but it is how my wordpress blog and Symfony 2.0 site co-exist. It is a real pain though I have a wordpress template and a Symfony template that must be kept updated. I really wish I could come up with a better solution to bring these to great tools together.
Here you go. I don't think anything below the wordpress controller line will ever be reached, but I left it in anyway
<IfModule mod_rewrite.c>
RewriteEngine On
# we skip all files with .something
RewriteCond %{REQUEST_URI} ..+$
RewriteCond %{REQUEST_URI} !.html$
RewriteCond %{REQUEST_URI} !.php
#RewriteCond %{REQUEST_URI} !.php
RewriteRule .* - [L]
# we check if the .html version is here (caching). If yes, don't redirect
RewriteRule ^$ /index.html [QSA]
RewriteRule ^([^.]+)$ /$1.html [QSA]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]
# if the 'myfeature' prefix is there, redirect to Symfony controller
RewriteCond %{REQUEST_URI} ^/myfeature/
RewriteRule .* index.php [QSA,L]
# otherwise, redirect to wordpress controller
RewriteRule .* wordpress/index.php [QSA,L]
# hidden frontoffice controller
RewriteRule ^index.php/(.*)$ /index.php [QSA,L]
# fo controllers
RewriteRule ^frontend.php/(.*)$ /frontend.php [QSA,L]
RewriteRule ^frontend_dev.php/(.*)$ /frontend_dev.php [QSA,L]
</IfModule>