htaccess redirect - wordpress code conflict - wordpress

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>

Related

Excluding a directory from wordpress htaccess

I have WordPress installed in a directory in the root and I used htaccess to point the domain name to it directly. I also have a CodeIgniter application in a directory in the root. There are two htaccess files one in the root folder (public_html) the other in the WordPress directory.
I cannot seem to make the CodeIgniter accessible. Please help.
htaccess in the root folder:
# 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 in wordpress directory
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /rainoilcom/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /rainoilcom/index.php [L]
</IfModule>
# END WordPress
htaccess in codeigniter directory
SetEnv TZ Africa/Lagos
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /recruitment/
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images|uploads|media|swf\.swf)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
I found the offending piece of code. "SetEnv TZ Africa/Lagos". Deleted it and I'm good.

.htaccess, WordPress and mod_speling

I've got a server that has in its root directory a bunch of subdirectories, one of which has a WordPress.
directory1
directory2
wordpress
directory3
All of these except for the WordPress were migrated from a Windows server to a Linux server which means that we've lost case insensitivity.
I want the WordPress to be able to serve a URL like http://www.example.com/~subdomain, so there's an index file in the root directory. I also have two .htaccess files, one in the WordPress and one in the root directory.
The following is the root directory's .htaccess.
This is where I'd like to put mod_speling's case insensitivity directives, but it conflicts with the rewrite rule.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~subdomain/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~subdomain/index.php [L]
</IfModule>
# END WordPress
Below is the WordPress subdirectory's .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~subdomain/wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~subdomain/wordpress/index.php [L]
</IfModule>
# END WordPress
I've tried using a symlink in the root directory to point to the WordPress directory's index.php. I set the symlink to be the DirectoryIndex but unfortunately it results in a lot of the links turning into 404s.
At this point I'm kind of stuck. Any ideas?

Avoiding Wordpress .htaccess rules on specific folder

I have Wordpress installed in root and a particular folder not related to Wordpress. I created a .htaccess file for the particular folder, but it is not working. The Wordpress .htaccess is always been called.
Wordpress .htaccess:
# 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
Particular folder .htaccess:
//301 Redirect Old File
Redirect 301 http://www.domain.com/folder/start.php http://www.domain.com/folder/index.php
When I load the above old address (that does not exists), the Wordpress .htaccess is called, instead of use the folder's .htaccess to redirect.
You don't need multiple .htaccess you can put all the rules on the WordPress main .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !^folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Use either:
RewriteRule ^folder/start\.php$ /folder/index.php [R=301,L,NC]
Or
Redirect 301 /folder/start.php http://www.domain.com/folder/index.php
Don't forget to change folder to your actual folder name.

htaccess redirect to subfolder with exception

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]

.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.

Resources