homepage Welcome to WebmasterWorld Guest from 54.167.185.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Need help with redirect
Haecceity




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

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

 

jdMorgan




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

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

Haecceity




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

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!

himalayaswater




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

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

Haecceity




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

Since my blog is now in the site root (www) doesn't that mean I need an htaccess file there?

jdMorgan




msg:3655800
 9:31 pm on May 21, 2008 (gmt 0)


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

Haecceity




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved