views:

49

answers:

1

I would like to rewrite two urls on my website so as they are more search engine friendly. How can I do this in my .htaccess? For the first I tried this, but got 404 errors:

RewriteRule ^research/([0-9][0-9])$ /research/$1/ [R]
RewriteRule ^research/([0-9][0-9])/$ /urt.php?func=viewresearch&rid=$1 
RewriteRule ^research/([0-9])$ /research/$1/ [R]
RewriteRule ^research/([0-9])/$ /urt.php?func=viewresearch&rid=$1

For the second I tried:

RewriteEngine on 
RewriteRule ^products/([0-9][0-9])$ /products/$1/ [R]
RewriteRule ^products/([0-9][0-9])/$ /viewad.php?adid=$1 

When I navigate to e.g. http://www.example.com/products/12/, it redirects but it looks like there are no external files loaded (Javascript, CSS, etc.). Why would that happen?

A: 

You’re probably using a relative URL, possibly just a relative URL path. In that case the relative URL is resolved from the base URL that is the current URL in case the base URL is not specified otherwise.

So when using a relative URL path reference like css/style.css on the base URL path /products/12/, it is resolved to /products/12/css/style.css instead of /css/style.css. Because here /products/12/ is the base URL path and not /urt.php. URL paths are not file system paths! The client does only know the URL and nothing else.

To solve this you have several options. The easiest would be to use the absolute URL path /css/style.css that is independent of the actual base URL path. Or you change the base URL by using HTML’s BASE element (note that this affects every relative URL). Or you adjust the relative URL path to fit the actual base URL path, so in case of /products/12/ use ../../css/style.css.

Gumbo