Htaccess in main directory conflicts with subdirectory - wordpress

I'm using two different opensource systems for a customer.
On the main directory I've installed wordpress.
In a sub directory (/shop) I've installed OpenCart 1.5.5
I want to have SEO url's enabled in OpenCart but when I enable this, my url becomes:
www.example.com/shop/category
The main htaccess from wordpress then checks if it knows the category and the post in wordpress and returns a 404.
If someone has got a solution for me I would be very pleased!
Thank you for your effort!
HTACCESS from Wordpress:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
HTACCESS from opencart:
Options +FollowSymlinks
Options -Indexes
<FilesMatch "\.(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

change the RewriteBase directive in the OpenCart .htaccess to
RewriteBase /shop/

Not sure if this works as I don't have a way of testing this locally. Change Wordpress htaccess to this:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/shop
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Related

redirect WordPress website and hide sub-directories at URL

I'm not expert using .htaccess
I need to direct any request at our website abutair.net, to open first WordPress workplace, then hide sub- folders at URL, such as an example below:
https://abutair.net/about-us/
Instead:
https://abutair.net/innerPages/wordpress-4.7.4/wordpress/about-us/
I've wrote at .htaccess of website root folder, the following:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?abutair.net$
RewriteCond %{REQUEST_URI} !^/innerPages/wordpress-4.7.4/wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /innerPages/wordpress-4.7.4/wordpress/$1
RewriteCond %{HTTP_HOST} ^(www.)?abutair.net$
RewriteRule ^(/)?$ innerPages/wordpress-4.7.4/wordpress/index.php [L]
</IfModule>
and at .htaccess WordPress inner folder, the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /innerPages/wordpress-4.7.4/wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /innerPages/wordpress-4.7.4/wordpress/index.php [L]
</IfModule>
# END WordPress
It direct successfully to WordPress pages, but the sub-folders show at URL.
Please advice me how can solve this issue?
Thanks in advance,

index.php added in url with virtualhost on wordpress

I created a virtualhost with MAMP. It works well when I go to example.dev. I just installed a wordpress on example.dev without any problems. When I display a page or a post, there is a /index.php which is added before the page name. For example : example.dev/index.php/pagename.
I can not access example.dev/pagename, i have a 404 error.
In permalink's options, it generates automatically /index.php/%year%/%monthnum%/%day%/%postname%/.
I selected http://example.dev/example-article/ but it is still not working.
I have a htaccess at the root
RewriteEngine On
# 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
If somebody has an idea...
Thank you !!
To this url /index.php/%year%/%monthnum%/%day%/%postname%/ will work on Apache server add this rule to .htaccess file
RewriteRule ^index.php/(.*)/?$ /$1/ [L]
Above the WordPress rules:
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Given that your .htaccess have the basic WordPress rules it would look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php/(.*)/?$ /$1/ [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
END WordPress

WordPress - redirect all pages to other domain and exception homepage and wp-admin

I need help with WordPress redirect. I think, that the simplest way is make this with htaccess file.
I want 301 redirect all pages from my site www.domain.com to subdomain web.domain.com, but I want have exception for homepage www.domain.com and for wordpress admin in www.domain.com/wp-admin/... and www.domain.com/wp-login.php
I have the basic wordpress htaccess settings:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
You can do:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule !^(wp-admin(/.*)?|wp-login\.php)?$ http://web.domain.com%{REQUEST_URI} [L,NC,NE,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Thanks for your help - I find, that I need both wp admin so I make this settings:
RewriteEngine on
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !/wpinstall(/.*)$
RewriteRule (.*) http://web.domain.cz/$1 [R=301,QSA]
And I install wp to subfolder wpinstall

Want to run wordpress in a subdirectory and keep my main site separate in the root

I have an eCommerce website in the root directory and want to move my blog to a subdirectory. I successfully made the move from another domain to this one but when I attempt to go to the blog home page it re-directs to my eCommerce site's home page.
The eCommerce site - http://www.heavytshirt.com
The blog location - http://www.heavytshirt.com/blog
The .htaccess file in the blog directory looks like this:
RewriteEngine on
RewriteBase /
# 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
And the .htaccess file in the root directory looks like this:
DirectoryIndex /mm5/merchant.mvc?Screen=SFNT
RewriteEngine On
RewriteRule ^mm5/admin.mvc? - [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^product/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Product_code=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^category/([^/.]+).html$ /mm5/merchant.mvc?Screen=CTGY&Category_code=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^product/([^/]+)/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Category_code=$1&Product_code=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^([^/.]+).html$ /mm5/merchant.mvc?Screen=$1 [L]
### End - Inserted by Miva Merchant
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^heavytshirt.com [nc]
RewriteRule ^(.*)$ http://www.heavytshirt.com/$1 [r=301,nc]
# 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
Currently I am able to type in a subsequent sub directory and get to a post - Like:
http://www.heavytshirt.com/blog/category/summershirts/
What can I do to make the blog home page come up when someone types in http://www.heavytshirt.com/blog
And not affect the main site at www.heavytshirt.com
I'm not looking into your apache configuration, since I believe it can easily be configured within WordPress.
Go into your WordPress administration panel, and move to Settings / General Settings.
Now change the values of WordPress Address (URL) and Site Address (URL) accordingly. Read this WordPress Codex article for more details.
Your issue is because you have set
DirectoryIndex /mm5/merchant.mvc?Screen=SFNT
Because /blog/ is a directory and the rules you have set are matching that as the directory index for /blog/ (because the directory actually exists).
You will have to combine the two Rewrite Directives to get the desired result (you don't need RewriteEngine On in there twice).
Probably better that you start from scratch testing line by line to make sure you get the desired result.
I can't test this, but you get the idea:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^mm5/admin.mvc? - [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^product/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Product_code=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^category/([^/.]+).html$ /mm5/merchant.mvc?Screen=CTGY&Category_code=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^product/([^/]+)/([^/.]+).html$ /mm5/merchant.mvc?Screen=PROD&Category_code=$1&Product_code=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^([^/.]+).html$ /mm5/merchant.mvc?Screen=$1 [L]
RewriteCond %{http_host} ^heavytshirt.com [nc]
RewriteRule ^(.*)$ http://www.heavytshirt.com/$1 [r=301,nc]
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

Exclude a folder/directory from RewriteRule

I have a pretty standard WordPress .htaccess with the following URL rewrites
# 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 is installed in my domain root. I have some other scripts in subfolders, e.g. /opencart These subfolders contain their own .htaccess files.
Unfortunately, it seems that WordPress hijacks the rewrites for some of these scripts sometimes.
How can I ask mod_rewrite to ignore WordPress rules for rewrites when encountered with specific subfolders e.g. opencart and to use the rules defined in the .htaccess within these subfolders instead?
You may try replacing the complete WP rule-set with this one:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI} !(folder1|folder2|folder3) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
In the .htaccess file in your site root, add the following ABOVE the WordPress .htaccess directives:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/subdirectoryname1/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/subdirectoryname2/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^/(folder1)/(.*) /folder1/$2 [R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L,R]
</IfModule>
# END WordPress

Resources