Forum Moderators: phranque

Message Too Old, No Replies

Ending up in the wrong directory using htaccess

         

designconscious

12:59 pm on Oct 22, 2010 (gmt 0)

10+ Year Member



Hi,

This is my first post and I'm a htaccess rookie.

I have a .htaccess issue at the moment that I've half solved but can't complete.

I'm trying to SEO my URL's and I'm ending up in a 'directory' and not the root. Here are my htaccess entries:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.co.uk [NC]
RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [L,R=301]

RewriteBase /

# SKU PRODUCT PAGE

RewriteRule ^([^/]+)/([^/]+)\.htm$ dfsku.lasso?model=$2 [L]

what I want to do is have a URL like this:

http://www.domain.co.uk/denon/SMART_302.htm


which re-writes to this page:

http://www.domain.co.uk/dfsku.lasso?model=SMART_302


But I want the SEO'd URL to remain in the address bar.

As I said I'm half way there, the above URL works, but all the links break because the site now thinks it's in the /denon/ folder (which doesn't actually exist)

How do I change my htaccess rules so the resulting rewritten URL remains in the root?

BTW: I've tried:

RewriteRule ^([^/]+)/([^/]+)\.htm$ http://www.domain.co.uk/dfsku.lasso?model=$2 [L]


And that works, but the SEO'd URL is replaced.

Hope you can help me, thanks in advance

Ian

jdMorgan

7:52 pm on Oct 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule ^([^/]+)/([^/]+)\.htm$ http://www.example.co.uk/dfsku.lasso?model=$2 [L]

Because you included the protocol and hostname, this rule invokes an external redirect, which tells the client (e.g. browser) to re-request the desired resource from a new URL.

 RewriteRule ^([^/]+)/([^/]+)\.htm$ /dfsku.lasso?model=$2 [L] 

Would probably work better.

Be aware that it is the client (browser or search robot) which resolve relatives links to the canonical URLs which it must request to fetch included objects and other pages. Therefore, if your page's URL is http://www.example.co.uk/denon/SMART_302.htm, a page-relative link like <img src="images/company-logo.gif"> on that page will resolve to http://www.example.co.uk/denon/images/company-logo.gif

As it's unlikely that you store your logo in a subdirectory of your Denon equipment directory, this image request will likely result in a 404-Not Found error.

The fix for this is to use only server-relative links or full canonical-URL links on pages whose URLs are rewritten from a "directory-like" structure to a script+query filepath. That is, use <img src="/images/company-logo.gif"> or <img src="http://www.example.co.uk/images/company-logo.gif">.

Jim