.htaccess file problems - wordpress

So I have a Joomla instance which is sitting in my ROOT directory. I have a Wordpress Multi-site installation sitting in the subdirectory /blog.
It seems like the server is having a hard time finding or getting sites in the /blog directory. Seems like it gets to the main /blog page fine but if I want to go to /blog/{sitename}, sitename being an instance of the Wordpress Mulitsite, it has a hard time getting there. Probably complicating matters is that I have Fancy URLs on both the Joomla instance as well as the Wordpress Multisite instance.
Both .htaccess files for Joomla and Wordpress Multisite are from stock installs of their respective applications (I'm 99% sure).
I'm going to post them here and see if anyone can see possible conflicts in the .htaccess
Joomla .htaccess with core SEF
version $Id: htaccess.txt 21064 2011-04-03 22:12:19Z dextercowley $
RewriteEngine On
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
RewriteBase /
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} (/[^.]*|\.(php|html?|feed|pdf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
END Joomla .htaccess
Now I have added this to the Joomla .htaccess file in hopes that it would not use SEF on the /blog folder but it doesn't seem to work. I am trying to exclude the blog directory from the top level .htaccess and just let the /blog .htaccess take over control of that subdirectory.
#RewriteCond %{REQUEST_URI} ^/blog/.*$
#RewriteRule ^.*$ - [L]
And here is my Wordpress .htaccess
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
Everything on the top level domain (Joomla) runs very fast when pages are requested.
The server eventually finds the /blog directory but it takes more time than it should. The really big problem is that when i go to one of the blog sites (/blog/sitename) it can take upwards of 8-10 seconds. And then once the page loads and I go to another page on that /blog/sitename like "About" it can take about the same amount of time.
Overall very frustrating. Any help is appreciated. I've been googling for awhile and have not found much help besides
#RewriteCond %{REQUEST_URI} ^/blog/.*$
#RewriteRule ^.*$ - [L]
And it has not helped the problem.
It seems like all the sites in the /blog directory are very slow to get to. I have about 6 in there and they are all very slow loading.

Well, I'm not sure if you're developing locally but one thing you could try would be to place all the Joomla files in their own directory and use .htaccess to resolve the site correctly - then you shouldn't have the Joomla .htaccess affecting your /blog directory.
Just a consideration. I'm not sure that it would resolve the issue entirely but at least then you could separate out the issue of 'is the Joomla .htaccess conflicting with the Wordpress .htacceess and causing a slowdown'.

Related

subfolder is redirecting to root and it shouldn't

My site is a wordpress site. If a user lands on http://www.example.com/subfolder (non-ssl), they are being incorrectly redirected to https://www.example.com (ssl but without the subfolder).
How do I stop this? They need to stay within the subfolder after being redirected to https://.
I"m using Really Simple SSL plugin within Wordpress. My .htaccess file contains this code:
#BEGIN ReallySimpleSSL
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /subfolder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subfolder/index.php [L]
</IfModule>
I've never been great editing the .htaccess file. Any help would be appreciated!
EDIT:..........
My .htaccess file is located within the subfolder. There is another .htaccess file located in the root, along with another website. I'm trying to keep users of the subfolder within the subfolder. *I've added a second IfModule to the above code.
The .htaccess in the root contains this code:
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Running in a fresh browser window, that I haven't used yet, I am getting the same results.
The issue most likely is that rule you implemented atop the configuration file in the subfolder:
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
It gets applied before anything else in the subfolder and it inconditionally rewrites all non-ssl requests to ssl. The issue here:
The capturing pattern ^(.*)$ gets applied to the relative path in the requests, that is only the section of the path from the subfolder base on. That is how rules in distributed configuration files get applied, this is clearly documented. That actually is one of the reasons why distributed configuration files add a lot complexeity and cause so many issues...
So instead you will have to either implement the https-redirection on top level, or use the absolute path or manually add the subfolder to the redirection target. I'd go with the second option:
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
The Really simple ssl plugin can cause such issues. Check the stop editing htaccess file option in the plugin settings and test with your htaccess code or try using the below snippet which works for me fine for subfolders/subdomains everything
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Header always set Content-Security-Policy "upgrade-insecure-requests;"

How to remove index.php from CodeIgniter3 install in subdirectory with Wordpress on root?

So the title of the question was a little difficult to come up with. Here's the deal, the CI3 install is like this: www.mydomain.com.au/apps/TGPS where TGPS is the CI application. Additionally, on the root of the web folder there is a Wordpress install. My question is, what is the .htaccess setup that I need to compress the URLs from:
www.domain.com/apps/TGPS/index.php/controller/function
to this:
www.domain.com/apps/TGPS/controller/function
At present I have this:
The top level .htacess is this:
# BEGIN WordPress
RewriteRule ^/apps($|/) - [L]
# END WordPress
The .htaccess in TGPS is this:
<IfModule mod_rewrite.c>
RewriteEngine On
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
and the .htaccess in application is the standard one.
Seems everything I try either breaks Wordpress, CodeIgniter or has no effect. Any help would be appreciated.
At first glance, you're missing a rewrite base:
RewriteBase /apps/TGPS/
Try bellow code
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]
Then the www to non-www:
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

Wordpress subdomain and multisite

Ok, here is the situation i can´t solve:
I have a WP multisite running on a server with 3 domains and 3 sites, and in that server i also have a subdomain running it´s own WP.
So, let´s say i have this MU sites:
site_1.com
site_2.com
site_3.com
And also i have this subdomain:
blog.site_1.com
The thing is if i go to this url: "site_2.com/blog" it show me the page using a 404 template with the subdomain theme style. Yeah!!
So, trying to access "site_2.com/blog", give me 404 using a theme that is in use on a subdomain named "blog" that is live over: blog.site_1.com.
My MU htaccess has this:
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
RewriteCond %{HTTP_HOST} ^blog.site_1.com [OR]
RewriteCond %{HTTP_HOST} ^www.blog.site_1.com$
RewriteRule ^(.*)$ http://site_1.com [R=301,L]
Last 3 lines are obviusly required in order to have a diferent WP instalation running on that subdomain that is actualy the "blog" folder on my public_html.
Also that "blog/" folder (where is installed the site under blog.site_1.com) has this default wp htaccess code:
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Maybe thats the problem, i have for one part a multisite running with 3 domains maping into the same server, but also on another part a subdomain running it´s own wp instalation and, badly, in this case i builded a page named "blog" that conflict with the "blog" folder that is actualy another site ?¿?¿?¿ jejej, it´s crazy, and at this point this is personal :) i need to know why i can´t make this working ok.
Any idea on how i can solve this thing? Thanks

non-www to www redirect not working for articles in subdirectory installation of WordPress

I am helping out with a website that has a main/root website as well as a WordPress installation in a sub-directory. The .htaccess file of the main site has rules to redirect non-www traffic to www:
RewriteCond %{HTTP_HOST} ^site\.com [NC]
RewriteRule (.*) http://www\.site\.com/$1 [R=301,L]
However, this has no effect on the WP site. For instance:
site.com would redirect to www.site.com
site.com/some-content-belonging-to-root-site would redirect to www.site.com/some-content...
site.com/wordpress does not redirect to www.site.com/wordpress
I added similar rules to the WordPress .htaccess, playing around to try to get the result I would expect, but the best I could come up with is this:
RewriteCond %{HTTP_HOST} ^site\.com [NC]
RewriteRule (.*) http://www\.site\.com/wordpress/$1 [R=301,L]
...which successfully redirects site.com/wordpress to www.site.com/wordpress, but does not redirect site.com/wordpress/a-blog-post.
I feel like I must be missing something simple or obvious, but hours of experimentation and research have not yielded a thing except that .htaccess files in sub-directories are not advised (but I think this is unavoidable in this case).
I would be grateful for any suggestions on how to fix the rewrite condition or rule to successfully redirect the post links of the WP site.
Thanks!
EDIT / ADDITIONAL INFO: I modified the RewriteCond to better match the incoming URLs, thinking that this might help, but it has the same effect. The base wordpress URL is rewritten, but article URLs are not:
RewriteCond %{HTTP_HOST}/wordpress/.* ^site\.com/wordpress/.* [NC]
RewriteRule (.*) http://www\.site\.com/wordpress/$1 [R=301,L]
I wouldn't think that it should matter, but just in case, I'll mention that the article URLs look like this:
site.com/wordpress/2014/05/16/article-slug
It turned out that the problem was not the rewrite conditions or rules, but the order in which they appeared in the .htaccess file.
I read a WP forum post in which someone suggested moving the rewrites to the top of the file for performance reasons. I gave it a shot just to see what would happen and noticed that the URL for the articles was affected - not in a good way, but affected nonetheless. I got something like this:
www.site.com/wordpressindex.php?/2014/05/16/article-slug
There were some rewrite rules to rewrite the base and redirect to the index given a nonexistent directory or file, which was what was building the garbled URL above.
In case it happens to help anyone else, I began with a .htaccess file that looked like this:
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
And ended up rearranging it to look like this, which now works to properly redirect all blog-related URLs to the www site:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteCond %{HTTP_HOST}/wordpress ^site\.com/wordpress [NC]
RewriteRule (.*) http://www\.site\.com/wordpress/$1 [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
Try:
RewriteCond %{HTTP_HOST} ^site\.com$ [NC]
RewriteRule (.*) http://www\.site\.com/wordpress/$1 [R=301,L]
And clean your browser history to make sure.
I also own a WordPress website and I was looking for www to non www redirect for my website : fasterthemes.com
The website is hosted in DigitalOcean and after struggling with several DAYS, I could figure out that all the solutions (.htaccess) codes available work fine if you've set the A record in your DNS settings properly. If it's not set then the redirection doesn't work !
So in my case,
I created one A record in my Digitalocean DNS like below :
i.stack.imgur.com/ie7f8.png
I added following code :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.(.)$ [NC]
RewriteRule ^(.)$ http://%1/$1 [R=301,L]
And now as you can see if you browse http://www.fasterthemes.com , it redirects you to fasterthemes.com. Earlier it was throwing an error.
I hope this helps.

htaccess redirect problems, Wordpress and static html site not redirecting properly

I'm having problems with a customer's website. I've created a new Wordpress site for him and now I'm having problems with htaccess redirecting.
Before I installed Wordpress on the server, there was two static basic HTML-sites. One in the public_html root using the main domain and a completely different subsite in a subfolder with a htaccess rewrite rule directing the subdomain into that folder.
Now there is Wordpress messing up the redirects. Wordpress of course made modifications to the original htaccess-file. In addition to that, the customer also had to change servers within the hosting provider to get newer php version so I had to write the htaccess file from scratch.
Here is the current htaccess-file :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /www/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /www/index.php [L]
</IfModule>
# END WordPress
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?subdomainurl.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subdomainfolder/
RewriteRule ^(.*)$ subdomainfolder/$1 [L]
Wordpress in installed in a folder named www and the url is being rewritten, it works beautifully. But I'm having problems with the subdomain. In the code above I've replaced the subdomain url with subdomainurl.com, the site lies in public_html/subdomainfolder/.
Now, when I type www.subdomainurl.com, the redirect works, the site is shown. But www.subdomainurl.index.html typed doesn't. It has to be written www.subdomainurl.com/subdomainfolder/index.html, so I'm clearly not writing the redirect right, adding the subdomain folder as well. I've tried to mingle with that htaccess but can't get it right. Everytime I try to change something I get a 404 in the main domain's Wordpress site.
At the moment these work:
www.maindomain.com/subdomainfolder/index.html
www.subdomainurl.com/subdomainfolder/index.html
And this doesn't, which I'm trying to do:
www.subdomainurl.com/index.html
I'm not a redirect expert, any help would be much appreciated.
Edit/Addon :
Here is the old code from the old server that redirected the subdomain to the subfolder and rewrote the url, it doesn't work anymore so I ditched it.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?subdomainurl.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subdomainfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdomainfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)?subdomainurl.com$ [NC]
RewriteRule ^(/)?$ subdomainfolder/index.html [L]
I don't see an entry in the htaccess file for just the subdomain and for the main domain.
Currently I'm using this code
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /www/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /www/index.php [L]
</IfModule>
END WordPress
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?subdomainurl.com$ [NC]
RewriteCond %{REQUEST_URI} !subdomainfolder
RewriteRule ^(.*)$ subdomainfolder$1
This loads the whole secondary domain (subdomainurl.com) as www.subdomainurl.com/subdomainfolder and it works like that (www.subdomainurl.com/subdomainfolder/index.html, www.subdomainurl.com/subdomainfolder/work.html etc.), but it still isn't what the customer really wanted. I still need to eliminate the subdomainfolder-part from the url by htaccess, so far I haven't had success. I suppose I haven't got it right on the final row of the code.

Resources