mod_rewrite help - change physical address to domain address

I am hoping for some help creating a .htaccess file / mod_rewrite rule to change the urls which are being displayed on a site which has just gone live.

The current .htaccess file contains:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sportsuk.org.uk/olympic-lessons/
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sportsuk.org.uk/olympic-lessons/index.php [L]
</IfModule>

# END WordPress

I need to add to this / amend this so that urls which currently show as http://79.170.44.91/sportsuk.org.uk/olympic-lessons/organising-committee/ display as http://www.sportsuk.org.uk/olympic-lessons/organising-committee/

Unfortunately my knowledge of mod_rewrite / .htaccess is limited so i’m hoping someone can help me out!

As a bit of background to the problem to date I have developed a WP site which is working correctly, it’s live and installed in a sub folder of the main website. It can be seen http://www.sportsuk.org.uk/olympic-lessons/. When you click on the page links the domain displays the physical address rather than the domain http://www.sportsuk.org.uk/

The domain for this site is held by a 3rd party and the WP files are hosted via my server (HeartInternet). The 3rd party has set up a redirect on their server / the domain to point at the physical address of my server and the only way we can get the site functioning correctly is to have the WP DB populated with urls pointing to the physcial address (79.170.44.91/olympic-lessons/…). If I change everything in the DB to http://www.sportsuk.org.uk/olympic-lessons/… it is causing the site to fail??

After spending almost three days now going back and forth with the 3rd party we seem to have got as far we can, although the site works the resulting urls aren’t correct as they show the physical address as opposed to the domain name.

I have set the site up entirely on my systems using a spare domain which I have, without any rewrites from the 3rd party etc. and can get the site working perfectly straight away in the scenario… unfortunately this was only to prove a point and ultimately the site has to work correctly on the right domain.

The 3rd party doesn’t want to release the domain to me as they provide other services on the domain and to make matters worse they can’t provide me with access to the server to manage a DB etc so we are at a bit of a stand off!

I’m now figuring that we are so close that a mod_rewrite rule could be the answer and everyone will be happy!

Any help would be much appreciated! (I have also posted a thead over on the WP forums to same effect as this in an attempt to resolve this as soon as possible!)

Thanks

JA,

Oh, my, too many things to comment upon!

  1. NEVER include <IfModule> tests in an .htaccess file - it’s extremely abusive of a server and SHOULD get you kicked off a shared server. In fact, this common noobie error is so prevalent, I have a Standard Rant for just this thing:

[rant #4][indent]The definition of an idiot is someone who repeatedly does the same thing expecting a different result. Asking Apache to confirm the existence of ANY module with an <IfModule> … </IfModule> wrapper is the same thing in the webmaster world. DON’T BE AN IDIOT! If you don’t know whether a module is enabled, run the test ONCE then REMOVE the wrapper as it is EXTREMELY wasteful of Apache’s resources (and should NEVER be allowed on a shared server).[/indent][/rant 4]

Don’t take that personally, just learn to KNOW what the code you’re using does and THINK about the effect of such code!

  1. RewriteBase is designed to UNDO mod_alias redirections. WHERE are your mod_alias redirections? DELETE the RewriteBase directive and learn to tell mod_rewrite which directory you want it to operate on (whether by moving your .htaccess to the directory or including it in the regex in your DocumentRoot). [After reading more below, I should also tell you that you NEVER include your domain in a RewriteBase even when you’re trying to UNDO a mod_alias Redirect.]

  2. Passing through the index.php (to your DocumentRoot OR your /sportsuk.org.uk/olympic-lessons/ directory???) will only pass the DocumentRoot’s index.php, not any of its supporting files (css, js, jpg, gif, etc).

  3. A WordPress error, the . character in the RewriteRule’s regex should be made optional so it will match a request made simply to the domain.

  4. Appending a trailing / tells visitor browsers that they are one level deeper in to the directory structure of your website, i.e., all the relative links will go missing. Yes, this can be overcome by using absolute links or the <base> tag but it’s just plain STUPID to force yourself to do that! Why in the world would you want to append trailing /'s?

Unfortunately my knowledge of mod_rewrite / .htaccess is limited so i’m hoping someone can help me out!

Certainly: READ the sticky post for this forum which contains some of the tutorial Article linked in my signature. Otherwise, actually READ the tutorial as the members who have read it have comprehended mod_rewrite almost immediately.

  1. DNS problems: Your website should be added as an addon domain (cPanel terminology) so that its DocumentRoot IS your olympic-whatever directory, not someone else’s DocumentRoot. With Shared accounts being so inexpensive these days, there’s no reason not to do this correctly.

  2. NEVER get into a “stand-off” position with a host: Get a good host (even if that means $10 for a new domain name - or going through the registrar to get your domain pointed to the new host’s DNS). Hosts are a dime-a-dozen so there’s no need to put up with any BS from a disreputable host.

Regards,

DK