install wordpress in blog folder + laravel in root folder - php

I installed laravel framework in root folder, and wordpress CMS in Blog folder
Laravel Works well, But WordPress does not work
I redirect no-www to www and http to https in laravel .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# 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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
mysite url: https://www.zanborasal.com
wordpress blog folder : https://www.zanborasal.com/blog
Do you have any idea how can I correct my Wordp=Press installation?

Just after RewriteEngine On if you add:
RewriteCond $1 !^(wordpress-folder)
That will exclude your Wordpress install and let you have your own htaccess settings within the wordpress-folder.

Related

How to configure .htaccess for a Laravel API app which is hosted on a subdomain?

I have a domain mydomain.com and a nginx space to host my website. The URL address mydomain.com is already in use and I don't want to buy another domain, so I created a subdomain myapp.mydomain.com. Then I created a laravel API app myapp for testing purposes and uploaded the code into /mydomain_com/myapp folder via a FTP client.
The problem now is I have to configure my .htaccess accordingly so the the app can run correctly.
At the current state, the homepage route / is working fine, but everything else is not working.
\mydomain_com\myapp.env:
...
APP_NAME=myapp
APP_ENV=local
APP_KEY=base64:U4v....
APP_DEBUG=false
APP_URL=https://myapp.mydomain.com
...
My routes are:
\mydomain_com\myapp\routes\web.php
Route::get('/', function () {
return view('welcome');
});
Route::get('/aaa', function () {
return view('welcome');
});
\mydomain_com\myapp\routes\api.php
Route::apiResource('os', OsController::class);
Now, when I go to https://myapp.mydomain.com I get this:
However when I try to visit https://myapp.mydomain.com/aaa and https://myapp.mydomain.com/api/os, I get this error ↓
Can You pls tell me what's the problem with my \mydomain_com\myapp\.htaccess ↓ ? Why is the homepage only working?
RewriteEngine On
RewriteBase /
# 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]
RewriteCond %{HTTP_HOST} !^subdomain
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
RewriteCond %{HTTP_HOST} ^subdomain
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/ [L]
Im using the htaccess which is already with the laravel and Im posting it below, it works fine with me
<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>
Also check if the mod_rewrite is enabled in your server, if you are using ubuntu and apache2 server enable the mod_rewrite using the command
sudo a2enmod rewrite
Kindly refer : Enable mod_rewrite
Update the content of .htaccess file in the root folder with this. It should work.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

Laravel site redirect to another laravel domain in ubuntu server

I have two domains, the first one is payment.propnex.net and the second one is digi.propnex.net.
I want the first domain to redirect me to the second domain immediately after visiting the url. How could I achieve that?
Server var/www/html
.htaccess from first domain
<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 ^(.*)$ http://digi.propnex.net/%{HTTP_HOST}/$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
EDIT. I created new .htaccess file in root directory of first domain and added
RewriteEngine On
RewriteCond %{HTTP_HOST} ^https://payment.propnex.net [NC,OR]
RewriteCond %{HTTP_HOST} ^http://digi.propnex.net [NC]
RewriteRule ^(.*)$ http://digi.propnex.net/%{HTTP_HOST}/$1 [L,R=301,NC]
Still when not redirecting

Laravel remove public from url and force https in .htaccess

How can I remove /public/ from url and auto force http to https?
my root .htaccess (I created it)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
RewriteCond %{HTTPS} !on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
public/.htaccess (by default laravel)
<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>
But it not works - no auto http to https redirect.
So I neet to combine removing public folder from url and forcing http to https using .htaccess
The problem you're having is that you've set your document root to be the root of the project. In your apache virtual host config you need to set the document root to be the public directory.
For example:
DocumentRoot /var/www/yourproject/public
That way, public doesn't appear in the URL.
If you're using shared hosting you'll want to move the root of your project to above public_html/, delete public_html, then rename your public directory to public_html. You can then go and modify the bootstrap files to use this path. You could also symlink it.
Add this two line into your Public Folder htaccess file
RewriteCond %{HTTPS} !=on
RewriteRule .* https://yourdomain.com%{REQUEST_URI} [R,L]
Full Code of your public/.htaccess
<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]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://yourdomain.com%{REQUEST_URI} [R,L]
</IfModule>
I think you need to enable rewrite_url with
$ sudo a2enmod rewrite
and
restart your apache server
$ sudo systemctl restart apache2
Your site-enabled/000-default.conf
DocumentRoot /var/www/html/yourapp/public
May be you can use
RewriteBase "yourapp/public/"
or refer this answer.
Rename server.php in your Laravel root folder to index.php
Copy the .htaccess file from /public directory to your Laravel root folder.
Put this code in .htaccess file of root directory of domain for removing 'public :
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
And for redirecting to https from http add following lines at the top in .htaccess file located in public directory of laravel project.
RewriteCond %{HTTP_HOST} your_domain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.your_domain.com/$1 [R,L]

Unable to get .htaccess to do 301 redirects correctly in a Laravel app

I got a URL Canonicalization issue and I want to redirect https://www.barreau.co/ar to https://barreau.co/ar
Please note that the following .htaccess code redirects https://www.barreau.co/ to https://barreau.co/ perfectly, but not with the /ar or /en that the Laravel multilanguage applications add.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.barreau\.co\/ar$
RewriteRule ^/?$ "http\:\/\/barreau\.co\/ar" [R=301,L]
# 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]
How can I make both https://www.barreau.co/ and https://www.barreau.co/ar redirect to non-www URLs correctly?
There's need to specify the locale imo.
Can you try this?
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
I tried it in a local environment with a fresh Laravel installation. It works fine. Make sure you also have mod_rewrite enabled and to restart your apache after doing the change.

Laravel 5 htaccess on shared web. Works both with /public/ URL and without

I am using Laravel 5.4 on shared web hosting. Site is running fine, without any functional problems. I am forcing HTTPS + WWW always.
But there are issue with URL path after redirect from invalid/non-existing page.
Instead of https://www.example.com/ in URL it shows https://www.example.com/public/
There are no redirect to /public/ if I go to any existing pages. Site is working fine in both ways, with or without /public/. For visitors it could be confusing that sometimes it is /public/ in end of URL and sometimes it is without. For example, normally I have URL https://www.example.com/about , but it is also working in https://www.example.com/public/about In this case I am also not sure about possible vulnerabilities.
I have 2 .htaccess files, one in project root folder public_html and another inside Laravel public folder public_html/public.
1) public_html/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
2) public_html/public/.htaccess
<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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(txt|xml)$ - [L]
# Force SSL + WWW
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
</IfModule>

Categories