I am moving a website to Wordpress, and using the Multiblog functionality. I'm not a htaccess expert by any means, but I do manage to use it regularly. So I'm reaching out here for some expert advice.
The website, www.blather.ie will use the same path for the sub-blogs as the old website. I need to keep legacy folders - like www.blather.ie/zeitgeist and some of the old content while publishing a Wordpress blog to the same path. I realised when I tried to this that 403 error would occur. So I found a workaround here and here.
Adding lines to my htaccess as described in those pages to my exist file didn't work. When I cleared out the htaccess file and started from scratch, I no longer got the 403 error - the content appeared, but without any themes/stylesheets. I checked the source, and saw that it was trying to pull the info from www.blather.ie/zeitgeist/wp-content... which doesn't exist - it needs to pull it from www.blather.ie/wp-content/...
Also, this 'fix' also started creating loops in the Admin back end. Not sure why.
So, here's my original htaccess file:
# BEGIN WordPress
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
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]
</IfModule>
# END WordPress
Here's the same htaccess with the recommended fix for the directory conflict problem, but which still causes the 403 error.
# BEGIN WordPress
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Fix 403 errors on existing directories; WordPress overrides.
RewriteCond %{REQUEST_URI} ^/(zeitgeist)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress
Here's a "clean" htaccess taken from the 1st recommended website - it cures the 403, but breaks paths, points to the wrong stylesheet location and causes redirect loops and 403s in the backend instead:
# 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]
# Fix 403 errors on existing directories; WordPress overrides.
RewriteCond %{REQUEST_URI} ^/(zeitgeist)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
So - my question - where am I going wrong with paths, and causing these damn feedback loops?
Thanks in advance!
Try this? Use the basic WP .htaccess, don't get fancy at all and instead drop a tiny .htaccess in each legacy folder (these are dirs right?) that disables rewrite in the folder.
This method worked for me as I needed to provide access to legacy folders as well. There are some options you may need to hit with casual variations for environments. There are a few ways to do this such as disable rewrite, allow dir access, show details, etc so I can't include a snippet for you at this juncture.
Related
I have a problem with a wordpress site as follows:
A website was built on http://example-domain.com.
I have build a wordpress site on http://example-domain.com/wordpress.
I want to delete everything in public.html folder and put a clean wordpress there.
The problem is that after I installed the clean wordpress, I keep getting redirected to the /wordpress subdirectory.
What I have tried:
Changed the site URL and home from example http://example-domain.com/wordpress to http://example-domain.com, copied a clean htaccess file in the new wp instalation.
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Before, I had 2 htaccess files, one just like the one mentioned above, that was located in the subdirectory and one in the root like this:
DirectoryIndex /wordpress/index.php
Options +FollowSymLinks
RewriteEngine On
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]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
<IfModule mime_module>
AddHandler application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
Extra info: It is not a cache or cookie nor browser issue.
Update:
I was watching the Network tab in dev tools on Chrome and saw this error.
Any help would be greatly appreciated!
Did you changed the existing database urls from http://example-domain.com/wordpress to http://example-domain.com ?
Export the existing database, open in a text editor, do find-replace for the url's(from subdirectory to root directory) as mentioned above. Then import it into the new database. Once done, a fresh htaccess like this in the public/html root folder should be working fine.
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
I have put my wordpress in public/blog folder in laravel. In my case after putting this RewriteCond $1 !^(blog) into .htaccess file I can install and access wordpress through www.mysite.com/blog. The only problem is when I change permalinks from this /blog/?p=123 to this /blog/%postname%/. It gives me error in laravel
NotFoundHttpException in RouteCollection.php line 161
so how can I have post with nice path like www.mysite.com/blog/my-post?
Just setting RewriteCond $1 !^(blog) is not enough.
Replace the line with RewriteCond %{REQUEST_URI} !^/blog/, so it'll ignore all URIs that start with /blog/.
Then don't forget to change the WP .htaccess too:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/ #change here
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L] #change here
</IfModule>
So I have been experiencing a rather brain confusing issue that seems to have quite a few conflicting issues.
On a new website (wordpress) I have setup we had lots of redirects that had query strings in them. Now all the redirect plugins I activated could not handle these so I found topics on here that helped me manually add these to the .htaccess file.
Here is an example (see lines that are **)
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
**RewriteCond %{QUERY_STRING} unit=32x10**
**RewriteRule ^unit\.php$ /available-units/32ft-x-10ft/? [L,R=301]**
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I have a long list of these RewriteCond / Rules.
We noticed that after a period of time these manual redirects I added were all being wiped and the .htaccess file was reverting back to the normal version (see below). To prevent this, I changed the file permission to not writable.
# 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
However, since doing this I am now unable to use Hide My WP and Really Simple SSL as they both require access to the .htaccess file.
Is there anything else I can do with these redirects that won't end up being wiped ?
Perhaps I am putting them in the wrong place within the .htacess file?
Your help would be much appreciated.
Many Thanks
MORE DETAILS ADDED
This is more query string redirects that are present....
RewriteCond %{QUERY_STRING} unit=32x10
RewriteRule ^unit\.php$ /available-units/32ft-x-10ft-32x10/? [L,R=301]
RewriteCond %{QUERY_STRING} unit=4579
RewriteRule ^unit\.php$ /available-units/32ft-x-20ft-4579/? [L,R=301]
RewriteCond %{QUERY_STRING} unit=4147
RewriteRule ^unit\.php$ /available-units/unit-ref-4147/? [L,R=301]
RewriteCond %{QUERY_STRING} unit=4768
RewriteRule ^unit\.php$ /available-units/2020-range-unit-ref-4768/? [L,R=301]
Try this solution:
RewriteRule ^(.*)$ unit.php/available-units/32ft-x-10ft/?unit=32*10 [L,QSA]
I have wordpress permalinks set up to /%postname% (note there is no trailing slash at the end).
However, wordpress is not redirecting any given page URL from the version with the trailing slash to the non trailing slash version. Any website header checking tool would return a '200' (OK) code for both versions (with and without the trailing slash). I am concerned this will have negative SEO consequences due to duplicate content. Therefore I want to have only one version of each page.
I am trying to modify the .htaccess file located on the wordpress directory so it removes the trailing slash at the end of any URL pretty much redirecting to the non trailing slash version of the URL.
I have Wordpress installed on a sub directory not on the root of my site i.e.
http://mywebsite.com/wordpress/
I tried the following code which I compiled by reading different questions posted on this website:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
The problem then is that I cannot login to wordpress admin. When I enter my user name and password on mywebsite.com/wordpress/wp-login.php
it typically used to redirect and enter to mywebsite.com/wordpress/wp-admin/
But now since the trailing slash is being stripped away from /wp-admin/ by the code I added to .htaccess then I get an error and cannot login to Wordpress.
I kept reading over this forums and then tried the following by playing around with the code and now I can login to wordpress but now the trailing slash is not being removed from any given URL.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/wp-admin/
RewriteCond %{REQUEST_URI} ^/wp-login\.php(.*)$
RewriteCond %{REQUEST_URI} ^/wp-admin$
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
Can anyone recommend what else I could do?
Pretty much all I want if for page URLs not to have a trailing slash at the end of the URL with the exception of the wordpress login page (mywebsite.com/wordpress/wp-login.php) and mywebsite.com/wordpress/wp-admin/
Keeping in mind the Wordpress install is on mywebsite.com/wordpress/ and not at root level.
Thanks so much!
Try these rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteRule ^((?!wp-admin/).+?)/$ /$1 [NC,NE,L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
I have a wordpress hosting site www.mysite.com/myBlog . The wordpress installation is done inside public_html/www/myBlog folder inside my host folder.
I also have a folder public_html/www/myName which redirects me to a domain myName.com
Although this works fine but inside myName folder i have files like index.html. acad.html, worexp.html
clicking on them i expect a behavior like
myName.com/index.html
myName.com/acad.html
myName.com/workex.html
though i get it as myname.com only.
I found htaccess rules in myName folder as :
Redirect http://mydomainName.com/myName/+
# 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
RewriteCond %{HTTP_HOST} ^mydomainName.com$
RewriteRule ^/?$ "http\:\/\/www\.mydomainName\.com\/myBlog" [R=301,L]
Can anyone help me with whats wrong with the htaccess file ?
More details:
My WordPress blog has something messed up. I can go to my blog and homepage works fine but when i try to go to any post it throws an 403 error. Apache forbidden.
Tried talking to web host for permissions its ok.
checked htaccess. Replaced code by default code stil not working.
Removed permalinks to default deleted htaccess created new permalinks.
Gave permissions to all the files in blog directory
Rewrote robots.txt Blog url is : www.windowsvj.com
Wordpress community is not able to suggest something very helpful too.
Current Redirect rule code in .htaccess is :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wpblog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wpblog/index.php [L]
</IfModule>
# END WordPress
This could be the result of FollowSymLinks being disabled in the server configuration. Simply adding Options +FollowSymlinks to the .htaccess file could do the trick.
Instead of using the flag [L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wpblog/
RewriteRule ^index\.php$ - [L] <---
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wpblog/index.php [L] <---
</IfModule>
# END WordPress
Try using [QSA]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wpblog/
RewriteRule ^index\.php$ - [QSA] <---
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wpblog/index.php [QSA] <---
</IfModule>
# END WordPress
How [L] works is if the RewriteRule matches
RewriteRule . /wpblog/index.php [L]
Then all other rewrites after this RewriteRule are ignored as stated on the Apache website
"In most contexts, this means that if the rule matches, no further rules will be processed." http://httpd.apache.org/docs/current/rewrite/flags.html
Here is a link with more information on .htaccess flags
http://httpd.apache.org/docs/current/rewrite/flags.html
Hope this works for you :P