I have a laravel site that client now wants opencart on the same domain, but running in the www.example.com/shop directory. I have put opencart in the public folder but I am having trouble with making the htaccess file redirect.
This is what I have done so far, but it just routes to laravel with route not found rather than going to the opencart folder. This is run on wamp at the moment, laravel works fine.
#if not from another platform(opencart) then load laravel
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !^/shop
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
#redirect to open cart directory
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ shop/index.php [L]
</IfModule>
Any ideas appreciated!
Change your .htaccess to this one.
#if not from another platform(opencart) then load laravel
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !^/shop
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
#redirect to open cart directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /shop/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^index.php [L]
</IfModule>
Related
WordPress has been installed on the root of the production server and my Lumen framework is in public_html/developer/api folder but when we try to access api folder through url it is showing WordPress 404 page not found error. One htaccess file has put in api (Lumen) folder and another in /developer/api/public.
htaccess file code inside api folder:
RewriteEngine On
RewriteBase /developer/api/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond $1 !^(index\.php|images|quotes|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /developer/api/public/index.php/$1 [L,QSA]
and inside api/public:
<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>
I have a website that home page is in site.pt/pt/home so I need to put in .htaccess but I don't know how...
I have this code:
<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}]
How can I do that?
Thank you.
Try putting this just after RewriteEngine On:
RewriteCond %{REQUEST_URI} !^/pt/home [NC]
RewriteCond %{REQUEST_URI} !^/pt/home/.* [NC]
RewriteRule ^(.*)$ /pt/home/$1 [R=301,L]
The two conditions are for skipping request that start already with /pt/home and the rule redirect all other requests there.
I've a laravel installed in /dev.domain.com/ and RootDocument is set to /dev.domain.com/public
The laravel works without any problem and then I install WordPress in newly created directory named "blog" under the laravel's public folder
Wordpress path : /dev.domain.com/public/blog
On localhost I'm can access /blog and setup wordpress as usual, however the problem come with I deploy to live server by cloning with git. The laravel path works fine but when I try to access /blog directory in public folder it returns 404 Not found
Below is the Laravel
/dev.domain.com/public/.htacess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect non ssl to ssl
# and don't redirect subdomain
RewriteCond %{HTTP_HOST} ^dev\.domain\.com [NC]
RewriteRule ^(.*) - [L]
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# 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]
</IfModule>
and Wordpress
/dev.domain.com/public/blog/.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
# Disable WordPress front-end
RewriteCond %{REQUEST_URI} !/wp-admin
RewriteCond %{REQUEST_URI} !/wp-includes
RewriteCond %{REQUEST_URI} !/wp-login\.php$
RewriteCond %{REQUEST_URI} !/wp-content
RewriteRule (.*) https://www.domain.com/ [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I've tried to add this one but no chance to make it works
RewriteCond %{REQUEST_URI} !^/blog
Above
RewriteRule (.*) https://www.domain.com/ [R=301,L]
Try this recipe, it works for me.
Add to Laravel .htaccess:
RewriteCond %{REQUEST_URI} !^/blog/ #
And change these lines in Wordpress .htaccess:
RewriteBase /blog/
RewriteRule . /blog/index.php [L]
I want to remove the index.php from the url to access the controller action. Therefore I added the following code in my .htaccess file in the public/ folder:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I would be grateful if anyone reply me and solve this issues.
Why don't use the default Laravel .htaccess file. You should go fine with it.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Lets say I'm trying to do a 301 redirect to /housing-associations from /table/09 - the following code is not redirecting. I'll include the whole .htaccess file. It's a Laravel installation. The other redirects work ie all urls are being directed to index.php and trailing slashes are being removed:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^fabric [NC,OR]
RewriteCond %{HTTP_HOST} ^www.fabric [NC]
RewriteRule ^/table/[0-9]{2} /housing-associations [R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Has anyone got any ideas. I cannot work out why this won't work?
Thanks
This should work for you:
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?fabric [NC]
RewriteRule ^table/[0-9]{2} /housing-associations [R=301,L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
The two HTTP_HOST conditions are merged into one, where the www. is optional. The leading slash from /table has been removed. Lastly, the L flag was added to prevent the index.php rule from running. If the L flag is not there, you'll get a Moved Permanently message from Apache.