I am running a Symfony app on DigitalOcean. I have setup the entire site and created VirtualHosts. I need to run WordPress as a subdirectory (/blog). From what I know Symfony tends to ignore subdirectories in /web so I created /web/blog and installed WordPress in it.
<VirtualHost *:80>
DocumentRoot /var/www/html/site.com/web
<Directory /var/www/html/site.com/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/symfony_error.log
CustomLog /var/log/apache2/symfony_access.log combined
</VirtualHost>
On localhost installations without VirtualHost this runs perfectly.
But on the live server, lets say at 21.21.21.21 I have Symfony running and 21.21.21.21/blog should open blog but it doesn't, instead goes to a Symfony 404. Whereas 21.21.21.21/blog/index.php runs the blog (WordPress).
The WordPress .htaccess which lives in /web/blog is as follows:
Options -Indexes
DirectoryIndex index.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
I have tried tinkering with this with some answers on the web, nothing changes.
Update your vhost so that you exclude your /blog directory from symphony rules. And you will also need to change to AllowOverride All since you are using .htaccess in /blog.
<VirtualHost *:80>
DocumentRoot /var/www/html/site.com/web
<Directory /var/www/html/site.com/web>
AllowOverride All
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/blog(/.+)? [NC]
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/symfony_error.log
CustomLog /var/log/apache2/symfony_access.log combined
</VirtualHost>
Be sure to restart apache after changes.
WordPress .htaccess Changes:
Options -Indexes
DirectoryIndex index.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
Related
I want to have a Wordpress and a Laravel under the same domain, so I can keep Wordpress and Laravel session always up and have Single Sign On between both. This objetive was achieved, but now I want to move laravel to another folder for security and define an Apache Alias with a sublocation. This is working too.
But the friendly URLs in laravel stoped to working. I think that I need make some change on .htaccess. I leave how I have my Apache2 config right now.
<VirtualHost *:80>
ServerName einflamatoria.inventeddomain.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/einflamatoria-foro-wp
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /educaforo-master /var/www/educaforo-master/public
<Location /educaforo-master>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride all
Require all granted
</Location>
</VirtualHost>
And Laravel .htaccess right now is
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
</IfModule>
With this configuration if I want to go to
einflamatoria.inventeddomain.com/educaforo-master/forums gives me a 404
but if I go to einflamatoria.inventeddomain.com/educaforo-master/index.php/forums works fine, but I need that it works without index.php.
I am working with laravel project. It works fine with php artisan. When I setup vhosts it's working only index page(Welcome page) but when I click on login,signup or any other pages it's not working. It shows page not found.
My httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/my_laravel/public"
ServerName laravel.dev
ServerAlias laravel.dev
ErrorLog "logs/laravel.log"
CustomLog "logs/custom.laravel.log" combined
<Directory "C:/xampp/htdocs/my_laravel/public">
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
And my hosts file
127.0.0.1 laravel.dev
.htaccess file inside public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
</IfModule>
You have to define URL rewrite in the public/.htaccess File.
Check if you have the correct settings there.
The Laravel default File looks like this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Just backup your .htaccess and try to copy paste this to your htaccess file and check if it works. If you use Laravels Authorization you also have to add this
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Maybe you also have to turn on the Modules mod_rewrite.c and mod_negotiation.c if they arent already.
You can do this by search and uncomment the line for the desired module in apache\conf\httpd.conf
If you want to customize your .htaccess for what ever reason there are many ressources available on the web.
I change my pc and install lamp on Windows 10 WSL.The main index works / but the routes is not. Here is my virtual host file.
<VirtualHost 127.0.0.2:80>
DocumentRoot /var/www/devroot/lara/panel/public
DirectoryIndex index.php
<Directory "/var/www/devroot/lara/panel/public">
Options All
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
And Here is the htaccess from project
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
The Error when i access a route link.
Not Found
The requested URL /lara/panel/public/admin was not found on this server.
Apache/2.4.18 (Ubuntu) Server at localhost Port 80
The Problem was the htaccess was hidden my bad i modified it to .htaccess from _htaccess and now it's working.
Your VHost Settings are incorrect. Laravel default serves to localhost:8000. You see it as output after using php artisan serve. Try this:
<VirtualHost *:80>
DocumentRoot /var/www/devroot/lara/panel/public
DirectoryIndex index.php
<Directory "/var/www/devroot/lara/panel/public">
Options All
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
I've tried to host a CodeIgniter website in Ubuntu server.
All other websites are working fine without any issues (the sever contains WordPress and Laravel applications). But this particular CodeIngniter website is not taking .htaccess file. I've spend a day to figure out the issue, but no luck.
Here is the details.
Website url structure: http://example.com/website_name
.htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Virtual host entry
<VirtualHost *:80>
ServerName example.com
ServerAlias example.com
DocumentRoot "/var/www/example.com"
<Directory "/var/wwww/example.com">
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
allow from all
</Directory>
</VirtualHost>
CodeIgniter config file
$config['base_url'] = 'http://example.com/website_name/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
And when I'm trying to access the website the output is as follows,
Not Found
The requested URL /website_name/test was not found on this server.
But if I add index.php, the the website is working without any issues. I've tried lot methods and it doesn't worked.
try this .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options -Indexes
RewriteEngine On
RewriteBase /website_name/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php [L]
</IfModule>
Add to your .htaccess
RewriteBase /website_name/
after your RewriteEngine on
I have a feeling MultiViews is probably causing some issues.
Change this in your VHOST
Options Indexes FollowSymLinks MultiViews
to this
Options Indexes FollowSymLinks
And also probably add a rewritebase to .htaccess Rewrite
RewriteBase /website_name/
Restart apache for config changes
Try changing your .htaccess like this.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
Or this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Not the ultimate answer but a good way to test if .htaccess is working at any level.
Create this .htaccess and put in root directory
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^test\.html http://www.google.com/? [R=301,L]
Then direct a browser to
http://example.com/test.html
If you end up on Google then you know .htaccess is working.
A useful way to debug .htaccess is to use its logging function.
Add this to your vhost's configuration:
RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9
You'll probably need to restart apache to get logging started.
Finally I've figured out the issue by spending an entire day. Here is the solution.
Updated virtual host entry.
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example.com/
# Additional section added to get the htaccess working in sub folder.
Alias /website_name/ /var/www/example.com/website_name/
<Directory /var/www/example.com/website_name/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
My intention is to speed up the performance of the cake app. I copied all the .htaccess files from my cake app, and despite the configtest saying all is ok, I still get an internal server error when I try and load the page. Is this the correct way to bring in .htaccess files from the app directory?
<Directory /var/www/html/aga-stag>
Options Includes FollowSymLinks
Require all granted
AllowOverride None
Order deny,allow
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^kwiksta\.com [NC]
RewriteRule ^(.*)$ http://www.kwiksta.com/$1 [L,R=301]
RewriteRule ^(red5|oflaDemo) - [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /app/
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
</Directory>
.htaccess files are valid apache conf syntax, so in principle all you need to do is copy and paste the htaccess file's contents into the right place. However don't blindly do that.
This is more appropriate for handling your kwiksta.com -> www.kwiksta.com redirects:
<VirtualHost *:80>
ServerName kwiksta.com
RewriteEngine On
RewriteRule ^ http://www.kwiksta.com{REQUEST_URI} [R=301,L]
</VirtualHost>
This snippet:
RewriteRule ^(red5|oflaDemo) - [L]
Is better handled by just putting (or symlinking) those folders (assuming that's what they are) into the webroot
And this is all that's required to then handle your CakePHP application:
<VirtualHost *:80>
DocumentRoot /var/www/html/aga-stag/app/webroot
ServerName www.kwiksta.com
AllowOverride None # No need for htaccess files now
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</VirtualHost>
Note that the document root points at the webroot folder as it should for a any and all production installs, which renders 2 of the 3 htaccess files irrelevant.
Be sure that the rewrite rules match the version of CakePHP you are using as they changed over time.