htaccess redirect to subfolder with exception - wordpress

I've searched quite a lot without finding a solution.
I have a wordpress blog in /_wp and something else in /other
What I'm trying to is that every request gets redirected to the WordPress. Except those to /other and its child directories. I also want the access to the blog to be rewritten. Few examples to make it clear:
/ --> /_wp/
/ablogpost --> /_wp/ablogpost
/other --> /other
/other/bingou --> /other/bingou
I've tried a few things but what seems the most logical to me is:
don't touch the .htaccess of /_wp/ and of /other/
edit the .htaccess of the root '/' by adding:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mywebsite.com$
RewriteCond %{REQUEST_URI} !^(/other|/other/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*)$ /_wp/$1
If you could tell me what is wrong there it would be great!
EDIT
After changing the index the subfolders were still not working here was my .htaccess back then:
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName site.com
# 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
EDIT 2
In the end it was a host problem thanks for your help though! Your answer works just well

You should follow this : http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
Your wordpress install is already in its own directory, so you just have to :
Copy /_wp/.htaccess to /.htaccess
Copy /_wp/index.php to /index.php
Edit /index.php :
require('./_wp/wp-blog-header.php');
Edit /.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Related

htaccess rewrite rule overpowers deny ip

I'm trying to deny access to my WordPress site while it's under construction. I have denied all other IP which appears to work fine when I comment out WP part of htaccess. When WP part of htacess is present and I access from forbiden IP, index.php page gets displayed, just without css or images.
Can someone explain how it happens and how to prevent it?
Thanks!
# ALLOW USER BY IP
<Limit GET POST>
Require all denied
Require ip 93.112.174.
</Limit>
# 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
One answer from user got deleted so I can't mark it as solution... Thanks! :)
Using rewrite rules was most simple way to achieve what I wanted, works fine on latest stable Apache 2.4.18
<If "-R '93.112.0.0/16'">
# 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>
<Else>
RewriteEngine On
RewriteRule ^ - [F]
</Else>

htaccess redirect - wordpress code conflict

I wonder if some kind soul can help me.
I have built a new WordPress site in a sub directory called 'wp'. Rather than moving everything (which I don't fully understand how to do) Id like to simply redirect the main page i.e. http://www.example.com to point to http://www.example.com/wp/ and for all pages to load from within that sub directory minues the /wp/ in the address line.
As per instruction from my web host I have added this redirect code to the .htacess file:
# Justhost.com
# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com
$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/wp/
# Don't change these line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /wp/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ wp/index.php [L]
However this is not working and my web host, who are not being very helpful, tell me that some existing code generated by WordPress is conflicting. This is the existing code in the .htaccess file:
DirectoryIndex index.html index.shtml index.xhtml index.wml index.perl index.pl index.plx index.ppl index.cgi index.jsp index.js index.jp index.php4 index.php3 index.php index.phtml index.htm home.htm default.htm index.fcgi default.html
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName zsr-art.org.uk
AuthUserFile /home/zsrarto1/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/zsrarto1/public_html/_vti_pvt/service.grp
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /index.php/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php/index.php [L]
</IfModule>
I'm using permalinks, I wonder whether this is causing a problem. Could someone please advise me as to where the conflict is and how to fix it?
Your RewriteBase in /wp/.htaccess is wrong (so your rule is).
In that file, replace this part
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /index.php/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php/index.php [L]
</IfModule>
by this one
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

wordpress redirects me to subdirectory folder

I have wordpress installed in subdirectory folder named "thumbs". I also followed the steps here.
Everything works fine but if I go to www.mysite.com/wp-admin it redirects me to www.mysite.com/thumbs/wp-admin, I don't want that to happen because I want the subdirectory folder to be secret.
So what I want is if I visit or somebody visit www.mysite.com/wp-admin I want the wordpress 404 error page to display. Thanks in advance for the help.
What am I missing?
You should modify your root .htaccess (not thumbs/.htaccess) file to add a rule for wp-admin, e.g. :
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin - [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Change your HTACCESS with this code
# Switch rewrite engine off in case this was installed under HostPay.
RewriteEngine Off
SetEnv DEFAULT_PHP_VERSION 53
DirectoryIndex index.cgi index.php
# 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

.htaccess remove subdirectory name from all URLs

I was digging the net and haven't found any proper solution for this issue. Basically, I want to remove subdirectory (subdirname) name from all URLs, e.g.:
http://test.com/subdirname/
http://test.com/subdirname/content/
http://test.com/subdirname/content/newpage
The website is based on Wordpress and located in /subdirname. I've got two .htaccess files, one in root directory:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !^(/var|/static)
#RewriteCond %{REQUEST_URI} !^(/index\.php|/var|/static)
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
RewriteCond %{HTTP_HOST} ^(www\.)?test\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/subdirname/
RewriteRule ^(.*)$ /subdirname/$1 [L]
and second in /subdirname/ directory:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdirname/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdirname/index.php [L]
</IfModule>
# END WordPress
If anyone has some tips how to solve it, please advice.
You should be able to set up WordPress to display at your root domain but be installed in the subdirectory. Just change ONLY the site URL under the Settings-> General screen. Leave the subdirectory in the WordPress URL box. Then you would login at http://yoursite.com/subdirectory/wp-admin, but folks visit your site at http://yoursite.com.

.htaccess with SilverStripe and WordPress

Ok, basically I need to be able to set my .htaccess so that it works for SilverStripe install in root directory and blogs installed in the /blogs directory. Here is what I have:
### SILVERSTRIPE START ###
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files web.config>
Order deny,allow
Deny from all
</Files>
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html
<IfModule mod_alias.c>
RedirectMatch 403 /silverstripe-cache(/|$)
</IfModule>
<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
# BEGIN Silverstripe
RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
# END Silverstripe
# BEGIN WordPress
RewriteBase /blogs/aquiman/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blogs/aquiman/index.php [L]
RewriteBase /blogs/aquipad/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blogs/aquipad/index.php [L]
# END WordPress
</IfModule>
### SILVERSTRIPE END ###
This of course does not work. And I know it is wrong, but I don't know enough to fix it. Please help me correct this to make it work right.
Thanks,
JH
One simple advise keep it separate i.e.
Keep SilverStripe related code in $DOCUMENT_ROOT/.htaccess with RewriteBase /
Keep Wordpress related code in $DOCUMENT_ROOT/blog/.htaccess with RewriteBase /blog/
Here is a modified Rewrite code you should use in $DOCUMENT_ROOT/.htaccess:
# BEGIN Silverstripe
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (?!^blog/)^.*$ sapphire/main.php?url=$1 [L,QSA,NC]
# END Silverstripe

Resources