co-existence of Symfony and wordpress in single webserver - wordpress

I have implemented my website in symfony2.4, but my blog in configured and installed in wordpress instance.
my wesite is under /var/www/html/website/ and the DocumentRoot is in httpd.cont is set to /var/www/html/website/web folder of symfony.
my wordpress is installed in /var/www/html/blog - I have created a soft link of the same in Symfony's web folder. But the wordpress site does not seem to work.
is there anything else that i need to configure?
my .htaccess file from sumfony's web folder looks something like this:
enter code here
<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]
RewriteCond %{HTTP_HOST} ^mywebsite\.com$
RewriteRule ^(.*) http://www.mywebsite.com/$1 [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/blog
RewriteRule ^(.*)$ app.php [QSA,L]
# 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>

I've managed to make the two cohabit with this .htaccess
<VirtualHost *:80>
ServerName yourdomain.com
#path to symfony
DocumentRoot "path/web"
AddDefaultCharset utf-8
DirectoryIndex app.php
<Directory "/path/web">
RewriteEngine On
Options +MultiViews
<IfVersion >= 2.3>
Require all granted
</IfVersion>
AllowOverride All
Allow from All
</Directory>
#path to blog
Alias /blog "/otherpath/blog"
<Directory /otherpath/blog>
DirectoryIndex index.php
RewriteEngine On
Options +MultiViews
<IfVersion >= 2.3>
Require all granted
</IfVersion>
AllowOverride All
Allow from All
</Directory>
</VirtualHost>

Related

htaccess redirects not working on Apache server

I want to redirect non-www to www version of the website. I've redirected many sites but never had this problem. I have a typical WP installation on Apache/2.4.27 (Ubuntu) server.
I've placed the following code before # BEGIN WordPress
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mywebsite.com [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301,NC]
I also tried this with no results.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mywebsite\.com [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]
</IfModule>
Everything I do, I get: FORBIDDEN - You don't have permission to access / on this server.
How to make this redirect to work? Is there something I should pay attention to on the server side?
Have you tried to modify httpd.conf?
RedirectPermanent is a good choice to replace .htaccess if not works.
example:
<VirtualHost *:80>
ServerName xy.example.com
RedirectPermanent / http://abc.example.com/
# optionally add an AccessLog directive for
# logging the requests and do some statistics
</VirtualHost>

VirtualHost Gives some 404 Not Found Error on Resources Wordpress Site

I have a wordpress site located on
/var/www/html/site
so I wanted to setup a Virtual host for Apache 2.4
<VirtualHost *:80>
DocumentRoot "/var/www/html/site"
ServerName www.site.com
<Directory "/var/www/html/site">
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
But while most of the resources do load, a lot of fonts and scripts are giving a Error 404 Not Found. Why is this?
Also what can I do? Are they restricting some but not others?
EDIT: Here's Some errors we're getting.
GET http://52.16.22.15/site/wp-content/plugins/djd-site-post/css/display.css?ver=4.0.1
52.16.22.15/:41
GET http://52.16.22.15/site/wp-content/plugins/codecanyon-5299073-bugmebar-a-simple-little-notification-plugin/bugme.css?ver=1.0.4
52.16.22.15/:46
As most of the site works, only some get requests are failing to get resources. I noticed it's mostly scripts and stylesheets.
This is what I have in my directory .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
</IfModule>
# END WordPress
# BEGIN wtwp_cache
# END wtwp_cache
# BEGIN wtwp_security
# END wtwp_security
There's more but it's on the level one above. But I am also reading that VirtualHost directories do not inherit .htaccess from parent directories. IS this true?
Try adding AllowOverride All
Like this,
<Directory "/var/www/html/site">
Order allow,deny
AllowOverride All
Allow from all
Require all granted
</Directory>

HTTP 404 with Post name permalink

Okay so I've just create the first page on this site. It works when I use the default permalink settings.
If I change the permalink settings to use Post name, then I get an HTTP 404.
I'm not sure what's gone wrong or if I've broken anything. Can anyone help me fix?
The site is hosted on apache.
Are you using XAMPP or MAMP? There are a couple of common hiccups with those environments, taken from the WordPress Codex: Fixing Permalink Problems
Users of XAMPP (Windows): Some versions of XAMPP do not enable
mod_rewrite by default (though it is compiled in Apache). To enable it
— and thus enable WordPress to write the .htaccess file needed to
create pretty permalinks — you must open apache/conf/httpd.conf and
uncomment the line LoadModule rewrite_module modules/mod_rewrite.so
(i.e., delete the hash/pound sign at the front of the line).
Users of WAMP (Windows): Some versions of WAMP (all versions?) do not
enable mod_rewrite or permit following SymLinks by default. To enable
the required functionality navigate to the apache/conf/httpd.conf
file, open with a text editor and uncomment the line LoadModule
rewrite_module modules/mod_rewrite.so (i.e., delete the hash/pound
sign at the front of the line). Then further down in the same file
there is a section that starts with the line "Options FollowSymlinks".
Change the second line in that section from "AllowOverride none" to
AllowOverride all. Save edited httpd.conf and restart all WAMP
modules. Your permalinks should now work.
You might also see Permalinks without mod_rewrite if your sandbox doesn't have mod_rewrite available.
Apache
If you are using Apache there are usually two other culprits to broken permalinks: .htaccess isn't being generated (because of permissions settings) or Apache's AllowOverride directive isn't enabled.
First, if you SSH into your server, do you see a generated .htaccess file in the root? If not, WordPress might not have permissions to write that file. It's also possible the file does exist, but that WordPress cannot edit it. In either case, you can chmod that file (and create it if it doesn't exist) to 666.
Next, ensure your Apache config has the following settings:
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
Finally, read through the Fixing Permalink Problems section of the WordPress Codex. There are several other tips and suggestions on why permalinks might not work.
In my case, firstly I had to update the .htaccess file inside my website root folder:
# 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
WordPress does this automatically if it has write permission. Otherwise it'll complain it can't write to it, and give the above code sample so you can manually update the .htaccess.
After that, I edited the apache2.conf file. In Linux, it resides in /etc/apache2/apache2.conf, there will be a section like this:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Change AllowOverride None to AllowOverride FileInfo.
Finally, execute the following commands:
sudo a2enmod rewrite
service apache2 restart
All these steps were necessary in order to work.
found this post on another site helped many people already
I finally managed to solve the problem! The solution: I was using a custom permalink structure http://kyl.fi/%category%/%postname%/. I removed the trailing slash (i.e. the last /) and voila. However, I'm quite sure I used a permalink structure with the trailing slash before without any problems, so I'm still confused and would be interested the hear more about this issue if somebody has an explanation.
All the standard permalinks have a trailing / in there.
in centos 8 and apache 2.4
look in /etc/httpd/conf.d
in your site .conf file add AllowOverride All, example like this
<Directory /path/to/site>
#add the following setting to allow .htaccess in your web dir to work
AllowOverride All
</Directory>
MY 80 LISTEN PORT
#Listen 80
<VirtualHost *:80>
DocumentRoot "/var/www/mysite.com"
ServerName www.mysite.com
# Other directives here
<Directory "/var/www/mysite.com">
Options FollowSymLinks
AllowOverride All
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mysite.com [OR]
RewriteCond %{SERVER_NAME} =mysite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
MY SSL VIRTUAL HOST:
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot "/var/www/mysite.com"
ServerName www.mysite.com
# Other directives here
<Directory "/var/www/mysite.com">
Options FollowSymLinks
AllowOverride All
</Directory>
ServerAlias mysite.com
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/mysite.com/fullchain.pem
SSLCertificateKeyFile /live/mysite.com/privkey.pem
</VirtualHost>
</IfModule>
Restart apache service.
Check your .htaccess (in my site the .htaccess is located in /var/www/mysite.com
My .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^helloWorld/?$ /index.php [NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
look helloWorld rewrite rule.
If you invoke url www.mysite.com/helloWorld and the browser show your homepage, the configuration is working and the permalink path to site works.
In my case, I am using the NGINX web browser with my WordPress installation. The fix is to add the following code snippet to the NGINX Directives:
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
expires max;
log_not_found off;
}
If you are using the excellent (open source) ISPconfig.org CPanel substitute, then go to your Sites page, under the Options tab, enter the above code snippet for NGINX Directives. ISPconfig has a feature to add common code snippets for quick access under the Options tab.
After making the above fix, I was able to use any of WordPress' Permalinks options.
Tested Working Solution:
in your apache2 config file for example:
/etc/apache2/sites-enabled/000-default.conf or mysite.conf etc ..
Make sure you have set param and not empty: ServerName www.example.com or 123.212.333.111
Also make sure You have set directory rules as below (Your rewrite rules may not have taken effect in the .htaccess hence you put it here and try finding out Why .htaccess does not work .htaccess not working apache):
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</Directory>
Must be 2 point check:
1. Add code to .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
And Permission of .htaccess file, must be: 644
My solution was add this code in /etc/apache2/sites_available/000-default.conf
<Directory "/var/www/mysite.com">
Options FollowSymLinks
AllowOverride All
</Directory>
I'm on Apache 2.4.46 (Ubuntu)
Thank you

Remove web/app_dev.php/ from url

I have my application in symfony 2 done.
And now I want to remove the web/app_dev.php/ from the url.
I read about this and after doing this:
php app/console cache:clear --env=prod --no-debug
And add .htaccess:
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
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>
After this I can use the url: localhost/test/web/
But it's not exactly my goal. I want to remove the web also.
And after this there's another problem. When I'm using localhost/test/web/ to access the page there's some stylesheet missing, but in app_dev.php everything looks good.
My question is, How can I remove the /web/ from the url?
And how can I have the stylesheet missing?
To remove the web you simply have to modify your apache configuration to make web as root directory.
DocumentRoot /yourpath/www/web
<Directory /youpath/www/web/>
Exemple of Apache Virtual Host Complete configuration :
<VirtualHost *:80>
ServerName www.yourdomain.com
DocumentRoot /yourpath/www/web
<Directory /yourpath/www/web>
Options FollowSymLinks
AllowOverride None
Require all granted
Allow from All
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</Directory>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/your_site.error.log
CustomLog ${APACHE_LOG_DIR}/your_site.log combined
</VirtualHost>
In production you should remove app_dev.php and set as root directory symfony web folder
Note: I don't add <IfModule mod_rewrite.c></IfModule> because if you don't have it you want apache to inform you that you are missing this module.
Apache/mod_rewrite configuration
To remove the /web part you can set RewriteBase additionally
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/
...
... or set your DocumentRoot directly to the web folder in your apache VirtualHost configuration.
stylesheet issue
The missing stylesheet in the prod environment can be resolved by invoking the assets:install command.
In the dev symfony will serve the files directly from the bundle's Resources/public folders because the default config_dev.yml contains assetic.use_controller: true.
The default production configuration has assetic.use_controller: false for performance reasons. Assets will not be recompiled and served through symfony on every request.
Now the assets in a bundle's Resource folder are not accessible until they are being moved/symlinked to the web folder where your webserver can find them which the assets:install and assetic:dump commands do.

Changing .htaccess file in order to allow subdomains

I'm hosting a Wordpress page in my domain and I would like to create a subdomain in order to host also a wiki page.
Example:
www.foowordpress.com -> Points to a Wordpress blog
wiki.foowordpress.com -> It should point to a Media Wiki page
It seems that the .htaccess generated by Wordpress redirects all subdomains to the Wordpress index page.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Could someone suggest how to change this .htaccess file in order not to redirect the wiki subdomain?
I've already configured my DNS manager and my VirtualHost for creating this subdomain.
As it turns out, I had not configured properly the VirtualHost file, there was nothing wrong with the .htaccess file.
Here is my VirtualHost file for the subdomain in case anyone finds it useful:
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin webmaster#foo.com
ServerName www.wiki.foo.com
ServerAlias wiki.foo.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /var/www/wiki.foo.com/
# Log file locations LogLevel warn ErrorLog
/var/log/apache2/wiki.foo.com/error.log CustomLog
/var/log/apache2/wiki.foo.com/access.log combined
</VirtualHost>

Resources