Welcome to WebmasterWorld Guest from 54.158.228.55

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Need help with redirect

     
5:28 pm on May 21, 2008 (gmt 0)

10+ Year Member



My wife and I both have Wordpress sites. Hers is in a directory in my site and by some kind of htaccess trickery that I really don't understand, people looking for her site see pages at her url (let's call it example.com) rather than at mine.

Now a couple of days ago I moved my Wordpress index file from a subdirectory ("blog") into the site root. That went well except that my wife's site is no longer working properly. The site comes up without styling and she can't log in to the admin area (which comes up as a 404).

Presumably there's something I need to change in the htaccess, which is in my site's root. Any idea what that might be?

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress

RewriteEngine On
RewriteCond %{HTTP_HOST} example.com$ [NC]
RewriteCond %{REQUEST_URI} !^/example/.*$
RewriteRule ^(.*)$ /example/$1

6:03 pm on May 21, 2008 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



If I were you, I'd reverse those two rules to start. The first rule may be "hijacking" any requests intended for her site.

You can also delete the <IfModule> - </IfModule> container pair, as it does nothing useful. Then delete the second "RewriteEngine on" as well, for the same reason.

If that doesn't help, then we'll need to know several things in order to help:

1) Please give an example URL for your blog (use example.com as the domain).
2) Please give an example URL for her blog (use example.org as the domain if different from yours).
3) Please give the corresponding server filepath for the URL in (1) above.
4) Please give the corresponding server filepath for the URL in (2) above.

(1) and (2) are what you'd type into the browser address bar to see a blog posting. (3) and (4) are the path to the files on the server -- like what you see when you navigate the site using FTP. Please note that we do not allow "personal" URLs to be posted here --for your good and ours-- so that's the reason for my request that you use "example.com" (and "example.org" if needed).

Thanks,
Jim

6:38 pm on May 21, 2008 (gmt 0)

10+ Year Member



Thanks for your reply, Jim. I'd already tried reserving the order of the two rules but it gave a 500 Server Error. Doing that plus having removed the opening and closing IfModule tags, and the extra "RewriteEngine On" still gives a 500 (that's on my wife's site -- mine's showing up fine).

However I'd rather not futz with the Wordpress code since Wordpress will (I think) overwrite any changes anytime I update my permalinks. If I'm wrong about that please let me know.

1. A sample URL from my site would be www.example.com/blog/wp-content
2. A sample URL from my wife's blog would be www.example.net/wp-content
3. The corresponding filepath for (1) above would be htdocs\www\blog\wp-content
4. The corresponding filepath for (2) above would be htdocs\www\example\wp-content

Thanks again for your help. I'm kind of embarrassed about having blown up my wife's site!

7:02 pm on May 21, 2008 (gmt 0)

5+ Year Member



You need to create two .htaccess files. To be frank .htaccess file is created automatically by Wordpress until and unless there is some problem. You can manually put both files as follows:
htdocs\www\blog\.htaccess
htdocs\www\example\.htaccess

No need to put anything in root
htdocs\www\

Code for htdocs\www\blog\.htaccess
---------

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress

---
Code for htdocs\www\example\.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /example/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /example/index.php [L]
</IfModule>
# END WordPress
7:10 pm on May 21, 2008 (gmt 0)

10+ Year Member



Since my blog is now in the site root (www) doesn't that mean I need an htaccess file there?
9:31 pm on May 21, 2008 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member




1. A sample URL from my site would be www.example.com/blog/wp-content
2. A sample URL from my wife's blog would be www.example.net/wp-content
3. The corresponding filepath for (1) above would be htdocs\www\blog\wp-content
4. The corresponding filepath for (2) above would be htdocs\www\example\wp-content

This isn't entirely consistent, since you said you'd moved your WP install to the root, but if I'm following you correctly, then I'd suggest something like this in your root .htaccess file:

RewriteEngine on
#
# Canonicalize my domain name
# If requested hostname contains "example.com" (any case)
RewriteCond %{HTTP_HOST} example\.com [NC]
# but isn't *exactly* "www.example.com" (must be www and lowercase, with no appended dot or port numbers)
RewriteCond %{HTTP_HOST} !^www\.example\.com$
# then redirect to canonical domain
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

# Canonicalize darling's domain name
RewriteCond %{HTTP_HOST} example\.net [NC]
RewriteCond %{HTTP_HOST} !^www\.example\.net$
RewriteRule (.*) http://www.example.net/$1 [R=301,L]
#
# Darling's site (assuming it has its own .htaccess file at /example/.htaccess)
RewriteCond %{HTTP_HOST} ^www\.example\.net
RewriteCond %{REQUEST_URI} !^/example/
RewriteRule (.*) /example/$1 [L]
#
# My site
# BEGIN WordPress
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress


The major change is that both rewrites are now requested-hostname-sensitive. The canonicalization redirect rules, aside from being a very good practice, also help simplify the WP rewrite rules.

Again, the <IfModule> container is a waste of space and CPU time -- all it does is make the WP code fail silently if mod_rewrite is not installed -- and I think that's a really dumb idea as a debugging technique... I susp[ect this was forced on the WP developers by hosting companies that don't support users' .htaccess files or mod_rewrite.

Jim

10:10 pm on May 21, 2008 (gmt 0)

10+ Year Member



That's absolutely amazing, thank you. Both sites are up and running and my sweetie will be very happy.

I should have explainedmore clearly that I have the innards of Wordpress in my /blog directory and the .htaccess and index.php files in the root. So wp-admin, wp-content, etc are in htdocs\www\blog\, while people see Wordpress as starting in the root and never see anything in the /blog directory.

Previously I had Wordpress running in the /blog directory (i.e. I had the .htaccess and index.php files there) and people saw a url like www.example.com/blog/archives/this-is-a-post. Now they just see www.example.com/archives/this-is-a-post, even though the Wordpress files are still in the /blog directory.

Anyway, thanks again. I'm bowled over by your generosity and expertise.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month