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>
Related
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 :)
Why won't this .htaccess force all subdirectories to use SSL?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
My particular use case: I have WordPress installed in a subdirectory, and I'm using mod_rewrite to "hide" that from my site visitors (docs are stored in example.com/wordpress, but appear to the browser as example.com). All good there. I added the HTTPS rewrite per instructions found in countless posts. But when I browse to example.com/nextcloud, all files are served up via HTTP!
There is an .htaccess file in my /nextcloud subdirectory. The only section pertaining to mod_rewrite reads as follows:
RewriteEngine on
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
RewriteRule ^remote/(.*) remote.php [QSA,L]
RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*
RewriteRule ^(?:\.|autotest|occ|issue|indie|db_|console).* - [R=404,L]
I only have a very basic knowledge of .htaccess files, but my understanding is that it works top-down (.htaccess in subdirectories can overwrite the settings of higher directories) except for mod_rewrite, which is a special case and works in the opposite fashion (the topmost directory takes precedence).
If my understanding is true, why is my code not working?
In your /.htaccess, add this above all other conditions/rules:
RewriteRule ^nextcloud(?:$|/) - [L]
That prevents WordPress from ever getting the requests.
In your /nextcloud/.htaccess, set
RewriteBase /nextcloud/
Also, shouldn't your root base should be just / since that is the public path to WordPress? How do static files route correctly? E.g. how does example.com/real/file get to example.com/wordpress/real/file?
So the title of the question was a little difficult to come up with. Here's the deal, the CI3 install is like this: www.mydomain.com.au/apps/TGPS where TGPS is the CI application. Additionally, on the root of the web folder there is a Wordpress install. My question is, what is the .htaccess setup that I need to compress the URLs from:
www.domain.com/apps/TGPS/index.php/controller/function
to this:
www.domain.com/apps/TGPS/controller/function
At present I have this:
The top level .htacess is this:
# BEGIN WordPress
RewriteRule ^/apps($|/) - [L]
# END WordPress
The .htaccess in TGPS is this:
<IfModule mod_rewrite.c>
RewriteEngine On
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
and the .htaccess in application is the standard one.
Seems everything I try either breaks Wordpress, CodeIgniter or has no effect. Any help would be appreciated.
At first glance, you're missing a rewrite base:
RewriteBase /apps/TGPS/
Try bellow code
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]
Then the www to non-www:
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
I have a application that uses rewrite conditions, and then I added wordpress. I could not get /blog to rewrite properly.
Please see below for both HTACCESS files in root, and /blog (where wordpress is installed). I need to create a reference in root to allow /blog to work properly (im guessing). But how can I do this without breaking my other rewrite rules?
/.htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?sn=$1 [QSA,L]
#RewriteRule ^([a-zA-Z0-9/%-]+)$ index.php?sn=$1 [QSA]
Then in wordpress my wordpres install folder, i am simply doing:
/blog/.htaccess
#for blog directory only
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
... and all other rw conditions needed for caching, etc
The reason the error was persistent with this dual HTACCESS setup was because the /blog/.htaccess file was missing an additional line:
RewriteRule . /blog/index.php [L]
Once added, it operated fine. No chances needed to go into the root htaccess to reference the /blog/ rewrite conditions. This allows for a wordpress install in a blog folder, and above references dual HTACESS rules
I'm having problems with a customer's website. I've created a new Wordpress site for him and now I'm having problems with htaccess redirecting.
Before I installed Wordpress on the server, there was two static basic HTML-sites. One in the public_html root using the main domain and a completely different subsite in a subfolder with a htaccess rewrite rule directing the subdomain into that folder.
Now there is Wordpress messing up the redirects. Wordpress of course made modifications to the original htaccess-file. In addition to that, the customer also had to change servers within the hosting provider to get newer php version so I had to write the htaccess file from scratch.
Here is the current htaccess-file :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /www/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /www/index.php [L]
</IfModule>
# END WordPress
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?subdomainurl.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subdomainfolder/
RewriteRule ^(.*)$ subdomainfolder/$1 [L]
Wordpress in installed in a folder named www and the url is being rewritten, it works beautifully. But I'm having problems with the subdomain. In the code above I've replaced the subdomain url with subdomainurl.com, the site lies in public_html/subdomainfolder/.
Now, when I type www.subdomainurl.com, the redirect works, the site is shown. But www.subdomainurl.index.html typed doesn't. It has to be written www.subdomainurl.com/subdomainfolder/index.html, so I'm clearly not writing the redirect right, adding the subdomain folder as well. I've tried to mingle with that htaccess but can't get it right. Everytime I try to change something I get a 404 in the main domain's Wordpress site.
At the moment these work:
www.maindomain.com/subdomainfolder/index.html
www.subdomainurl.com/subdomainfolder/index.html
And this doesn't, which I'm trying to do:
www.subdomainurl.com/index.html
I'm not a redirect expert, any help would be much appreciated.
Edit/Addon :
Here is the old code from the old server that redirected the subdomain to the subfolder and rewrote the url, it doesn't work anymore so I ditched it.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?subdomainurl.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subdomainfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdomainfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)?subdomainurl.com$ [NC]
RewriteRule ^(/)?$ subdomainfolder/index.html [L]
I don't see an entry in the htaccess file for just the subdomain and for the main domain.
Currently I'm using this code
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /www/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /www/index.php [L]
</IfModule>
END WordPress
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?subdomainurl.com$ [NC]
RewriteCond %{REQUEST_URI} !subdomainfolder
RewriteRule ^(.*)$ subdomainfolder$1
This loads the whole secondary domain (subdomainurl.com) as www.subdomainurl.com/subdomainfolder and it works like that (www.subdomainurl.com/subdomainfolder/index.html, www.subdomainurl.com/subdomainfolder/work.html etc.), but it still isn't what the customer really wanted. I still need to eliminate the subdomainfolder-part from the url by htaccess, so far I haven't had success. I suppose I haven't got it right on the final row of the code.