Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

the root directory http: // www .mydomain .com (SF won't let me post hyperlinks - rep is too low) has a catchall index.php page in it, and an .htaccess file. Within this root directoy I have a wordpress/ directory which contains (suprise surprise) a wordpress installation.

My goal is that when the user types in http: // www .mydomain .com they are instead taken to http: // www .mydomain .com/wordpress

Here is my rewrite rule:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/wordpress
RewriteRule ^/(.*)$ http://%{SERVER_NAME}/wordpress/$1 [L]

At the moment it appears to do nothing - it still loads index.php within the root directory.

What should my rewrite rule be (I'm assuming the one I'm using is wrong)?

share|improve this question
    
Server's tech support suggested 'Redirect permanent /index.php http:// www. mydomain. com/wordpress' but that won't work because you'll always have 'wordpress' in the user's address bar. They shouldn't be seeing 'wordpress' in there at all... –  Tom Auger Jan 12 '11 at 15:47
    
Furthermore, that only works for calls to index.php. What about calls to, say, wp-login.php etc? –  Tom Auger Jan 12 '11 at 16:02

3 Answers 3

up vote 1 down vote accepted

The Correct way to use WordPress in its own directory is to copy the index.php file from the WordPress directory and change the line this line:

require('./wp-blog-header.php');

To this:

require('./your_wordpress_directory/wp-blog-header.php');

When you do this go back to your admin options and re save your permalinks and WordPress will automatically rewrite your .htaccess based on your site url and WordPress url options selected.

These can also be defined in wp-config.php

Use this if WordPress lives at http://example.com/wordpress but you want users to access your site by typing in example.com.

define('WP_HOME', 'http://example.com');

define('WP_SITEURL', 'http://example.com/wordpress');
share|improve this answer
    
Outstanding. I had read the instructions on moving index.php out of the wordpress/ directory, but making WP_HOME different from WP_SITEURL was the missing link! Rather than hard-code it in the wp-config.php file, I preferred to change it directly in the database - for others reading this post, you're looking for the wp_options table, and you're going to browse for the options called 'siteurl' and 'home'. Thanks for the help, Chris. –  Tom Auger Jan 14 '11 at 13:16

Specifically what is wrong is that you are not telling it what to do with that match. The [L] by itself tells it that is the last rule to evaluate if it matches, but there is no action on that match. The most typical case is [R] to perform a redirect.

If you are looking to redirect http://www.domain.com/ to http://www.domain.com/wordpress/ via a redirect, you should be able to do this simply with:

RewriteEngine on
RewriteRule ^/$ /wordpress/ [R,L]

This will take a URL that has nothing after it (that is, just the www.domain.com) and redirect it to the relative path "/wordpress". So when you hit www.domain.com/, you will get redirected to www.domain.com/wordpress/, but if you hit www.domain.com/wordpress/?pageid=1, or even www.domain.com/some_specific.html the rewriterule will not be hit, because it doesn't match the ^/$ rule.

share|improve this answer
    
Wow, thanks for the quick response! Unfortunately, this didn't do anything. It's still going to /index.php on the root directory. –  Tom Auger Jan 12 '11 at 15:46
    
Looking at your regexp, wont that only work if I type: http:// www. mydomain .com/ <-- note trailing slash? If there's no slash, then this will not even trigger... –  Tom Auger Jan 12 '11 at 16:03
    
afaik, the R affects the browser. If it's not included, the rule will still do an internal redirect (R by itself issues a 302 redirect, R=301 issues...obviously...a 301 redirect). In some cases you don't want the browser url to change –  DTest Jan 12 '11 at 16:11
    
Yes, this will only match if the URL ends w/ a slash. However, browsers append that to the URL, so it should still work. I tested in FF and Chrome. –  Alex Jan 12 '11 at 16:22

try this:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/wordpress
RewriteRule ^(.*) http://%{SERVER_NAME}/wordpress/? [L]
share|improve this answer
    
What does the '?' in your Regexp do? –  Tom Auger Jan 14 '11 at 13:16
    
let pass all the stuff after "wordpress/" –  Nicola Boccardi Jan 15 '11 at 1:42
    
Are you sure? In the match part of the regular expression I believe that most symbols are treated literally (ie: you are actually putting a "?" into your address). See the documentation here: httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule. Am I mistaken? Can you point me to documentation that supports this? –  Tom Auger Jan 18 '11 at 18:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.