Change the URL, but all sub pages ahve old URL - help please

Hi,

my site files are in folder named trade-th.com on my host.

The URL was www.trade-th.com

www.trade-th.com/trade-th.com

But I wanted to change my site URL to

www.classified-thailand.com

so in the Domains I Edited the Domain URL to

www.classified-thailand.com/trade-th.com

the page loads at www.classified-thailand.com

but many of the subpages will not load as they still have the http://trade-th.com (example)

http://trade-th.com/32-national-communications-day-2012/details.html

I would like all pages, login, register, etc to have the new classified-thailand.com/32-national-communications-day-2012/details.html

how can I correct this problem ?

your help greatly appreciated.

Hi Ray,

The easiest is to check the domain requested using mod_rewrite and, if trade-th.com or www.trade-th.com, redirect to www.classified-thailand.com. While I do cover such an action in my signature’s tutorial, an example would be (keeping the trade-th.com directory - not sure this is necessary - and assuming only lower case characters, dots and slashes):

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\\.)trade-th.com$ [NC]
# match trade-th.com domain name without regard to case
RewriteRule ^trade-th.com/([a-z./]*)$ http://www.classified-thailand.com/trade-th.com/$1 [R=301,L]
# only match directory trade-th.com directory's requests and redirect to www.classified-thailand.com with the same request.

Regards,

DK

Hello dklynn, thank you for your reply, and solution, much appreciated :slight_smile:

I will add that code, and report back with the results,

best wishes :slight_smile:

Ray,

No problem. Since I was unsure about your DocumentRoot (is it the trade-th.com SUBDIRECTORY?), I almost expect you to have a problem. I’m more than willing to help with further definition.

Regards,

DK

Hello dklynn, thank you for you offer of help :slight_smile:

I am still in the process of migration files from trade-th.com to http://classified-thailand.com/

Then I will implement your re-direct code for trade-th.com pages :slight_smile:

As soon as I can see light I will write and update you,

many thanks,

Ray :slight_smile:

Hello dklynn, Here is an update to my URL re-directing

I am using this page to check the url re-direct codes http://www.ragepank.com/redirect-check/

My old url tests perfectly http://www.trade-th.com (this old URL is now re-directed to http://classified-thailand.com)

But http://classified-thailand.com does not pass 100% with

http://classified-thailand.com/default.aspx returns a HTTP/1.1 500 Internal Server Error response

http://www.classified-thailand.com/default.aspx returns a HTTP/1.1 500 Internal Server Error response

http://classified-thailand.com/index.aspx returns a HTTP/1.1 500 Internal Server Error response

http://www.classified-thailand.com/index.aspx returns a HTTP/1.1 500 Internal Server Error response

this is the code i have in my .htaccess

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.classified-thailand\.com
RewriteRule (.*) http://www.classified-thailand.com/$1 [R=301,L]

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^./index\.html
RewriteRule ^(.
)index.html$ http://www.classified-thailand.com/$1 [R=301,L] RewriteCond %{THE_REQUEST} ^./index\.php
RewriteRule ^(.
)index.php$ http://www.classified-thailand.com/$1 [R=301,L]

your advice and feedback greatly appreciated :slight_smile:

Hi Ray!

Okay, old URL redirects to new URL successfully. Then let’s look at your code and problems.

First, ASPX pages suggest an IIS rather than Apache. I understand that there are two versions of pseudo-mod_rewrite created by M$ to emulate Apache’s actions but you’ll need to wait for Wyatt to come by or …

Let me assume that your domains are co-located (you’ve not said otherwise and this can have a major impact).

PLEASE wrap your code in [noparse]

...

[/noparse] tags as that preserves the code when quoting for a reply.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\\.classified-thailand\\.com
# Note that this will redirect if the www is not present OR if CaMeL CaSe is used on the domain name (don't forget the No Case flag)
RewriteRule (.*) http://www.classified-thailand.com/$1 [R=301,L]

[COLOR="#A9A9A9"]RewriteEngine on[/COLOR]
# This is only needed ONCE (to ensure you're not in "Comment Mode")
[COLOR="#A9A9A9"]Options +FollowSymLinks[/COLOR]
# This should already be in the httpd.conf file, i.e., not necessary to repeat this directive
RewriteCond %{THE_REQUEST} ^.*/index\\.html
# You understand the basic problem of using %{THE_REQUEST} but you still don't need the ^.* before the /
#    UNLESS you're trying to match index.html requests in all subdirectories, too
RewriteRule ^(.*)index.html$ http://www.classified-thailand.com/$1 [R=301,L] 
# Hmmm, subdirectories of classified-thailand.com with index.htmls, eh?
# Are you expecting to capture / or sub/? I don't understand your intent (but that's my problem)

RewriteCond %{THE_REQUEST} ^.*/index\\.php
# ditto the above comment
RewriteRule ^(.*)index.php$ http://www.classified-thailand.com/$1 [R=301,L]
# ditto the above comment

With that review, http://classified-thailand.com should redirect every time it’s requested and the index.(html|php) do not match so those two redirections should not take place.

The bottom line is that 500 errors are normally caused by malformed code (read syntax error). Other than the comments I made above, none of which dealt with incorrect syntax, I’d have to guess that your IIS does not honor the full mod_rewrite code. With %{yadda-yadda} representing Apache variables, I’d guess that %{THE_REQUEST} may not be recognized by IIS.

Sorry to guess at the IIS impact but that was not evident in the original question.

Regards,

DK

Hello David, I see you are in Auckland, my home city, now I am a Kiwi in Bangkok :slight_smile:

Yes you were correct the domains are co-located.

Thank you for all your detailed explanation, and for the code, I have uploaded the new code and all is behaving correctly.

I also contacted my hosting server about the - http://classified-thailand.com/default.aspx returns a HTTP/1.1 500 Internal Server Error response

As I remember that they made a change their end for trade-th.com ( well I think that is what removed the Error)

Thank you again David, and best wishes,

Ray :slight_smile:

Hi Ray,

So glad that it’s all working out fine for you now.

Rainy yesterday here but that’s great as it hides the tears (of frustration with Team New Zealand). I don’t expect much from them tomorrow but cling to that little bit of hope.

Enjoy Thailand!

Regards,

DK

Hello David,

Your help again please.

I would like this:

http://trade-th.com/26-colloidal-silver-15-ppm-spray/details.html

redirected to this

http://www.classified-thailand.com/16-colloidal-silver-15-ppm/details.html

I tried this…but nope !

RewriteCond %{HTTP_HOST} ^trade-th.com/26-colloidal-silver-15-ppm-spray/details.html$ [OR]
RewriteCond %{HTTP_HOST} ^www.trade-th.com/26-colloidal-silver-15-ppm-spray/details.html$
RewriteRule (.*)$ http://www.classified-thailand.com/16-colloidal-silver-15-ppm/details.html/$1 [R=301,L]

so I tried this:

Redirect 301 /26-colloidal-silver-15-ppm-spray/details.html http://www.classified-thailand.com/16-colloidal-silver-15-ppm/details.html

but nope !

Thank you again David, and best wishes,

Ray :slight_smile:

Hi Ray,

Drowning in my misery/frustration so thanks for the wake-up call (PM).

Problem: http://trade-th.com/26-colloidal-silver-15-ppm-spray/details.html redirected to http://www.classified-thailand.com/16-colloidal-silver-15-ppm/details.html.

First, comments on your code:

RewriteCond %{HTTP_HOST} ^trade-th.com/26-colloidal-silver-15-ppm-spray/details.html$ [OR]
# The {HTTP_HOST} will never go beyond (nor include) the first / so you needed to ignore the domain
# Remember, we took care of the domain redirections first so every mod_rewrite rule will only be dealing with www.classified-thailand.com!
RewriteCond %{HTTP_HOST} ^www.trade-th.com/26-colloidal-silver-15-ppm-spray/details.html$
# Ditto
RewriteRule (.*)$ http://www.classified-thailand.com/16-colloidal-silver-15-ppm/details.html/$1 [R=301,L]
# RewriteRule ^26-colloidal-silver-15-ppm-spray/details[SIZE=5]\\[/SIZE].html$ 16-colloidal-silver-15-ppm/details.html [R=301,L]
#   is likely what you were after (I didn't understand why you wanted 26-colloidal-silver-15-ppm-spray/details.html after the redirection)

and

Redirect 301 /26-colloidal-silver-15-ppm-spray/details.html http://www.classified-thailand.com/16-colloidal-silver-15-ppm/details.html

Actually, that looks like it should have worked.

All you needed (I believe) was

RewriteRule ^26-colloidal-silver-15-ppm-spray/details\\.html$ 16-colloidal-silver-15-ppm/details.html [R=301,L]

Tip: Ordering of activities in the .htaccess file:

  • Apache core directives (DirectoryIndex, ErrorDocument, etc).
  • mod_rewrite
  • [LIST=1]
  • General applicability items (Domain Redirections, etc.)
  • General applicability items (e.g., replace -'s with _'s, .html with .php, etc)
  • RewriteRule sets (from most specific to most general)
    Be sure to use RewriteCond statements to skip the already performed redirections!
    [indent]This is generally the case with WP redirections where EVERYTHING (not a file/directory) is redirected to index.php.[/indent]

[/LIST]

I hope that both made sense and helped.

Regards,

DK

Hi David,

Thank you for your quick informative reply, especially after misery/frustration!

Ok so I pasted your code:

RewriteRule ^26-colloidal-silver-15-ppm-spray/details\\.html$ 16-colloidal-silver-15-ppm/details.html [R=301,L]

into the .htacces file in www.trade-th.com folder

and it did not work 100% but I also have in the .htacess this:

RewriteCond %{HTTP_HOST} ^trade-th.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.trade-th.com$
RewriteRule (.*)$ http://www.classified-thailand.com/$1 [R=301,L]

now when I say it did not work 100% I mean it redirected me to http://www.classified-thailand.com with a message saying: This listing does not exist!

Ok now with no additional .htaccess code:

RewriteRule ^26-colloidal-silver-15-ppm-spray/details\\.html$ 16-colloidal-silver-15-ppm/details.html [R=301,L]

http://trade-th.com/26-colloidal-silver-15-ppm-spray/details.html shows: This listing does not exist!

your help appreciated :slight_smile:

Hi Ray!

Yea, EnZed is in a state of mourning … for another three years!

Okay, okay, of course 16-colloidal-silver-15-ppm doesn’t exist! If you’re going to redirect to such a “ridiculous” directory name, you’ve GOT to throw Apache a bone … er, RewriteRule. Was that what you were trying to do with your $1 which I removed (after details.html/)?

Back to tips:

When I start with my mod_rewrite code, I like to specify ALL the tasks I want mod_rewrite to perform for me, sort them as noted before then code them. I see:

  1. Change domain name

1a. It also appears that you want to force www on classified-thailand.com

  1. Change one subdirectory to another

and, the “Missing Link” is to

  1. Redirect the “missing” subdirectories to details.html … AND provide the subdirectory name to details.html so it knows what do do (like WP’s index.php which does EVERYTHING).
# .htaccess in DocumentRoot of both trade-th.com and classified-thailand.com

# mod_rewrite code only - you can take care of your DirectoryIndex, Options -Indexes, ErrorDocument, etc.
RewriteEngine on

# force www.classified-thailand.com (#1 & #1a)
RewriteCond %{HTTP_HOST} !www\\.classified-thailand\\.com$ [NC]
RewriteRule .? http://www.classified-thailand.com%{REQUEST_URI} [R=301]

# Redirect 26-colloidal-silver-15-ppm-spray/details.html to 16-colloidal-silver-15-ppm/details.html (#2)
RewriteRule ^26-colloidal-silver-15-ppm-spray/details\\.html$ 16-colloidal-silver-15-ppm/details.html [R=301]

# The Missing Link! Redirect non-directory requests to details.html in DocumentRoot with dir={value of the non-directory}
RewriteCond %{REQUEST_FILENAME} ^([-a-z0-9]+)/details\\.html$
RewriteCond %{DOCUMENT_ROOT}[SIZE=5]/[/SIZE]%1 !-d
# I don't think you need the [SIZE=5]/[/SIZE] but I put it in here for you to test and report back, if you would be so kind
RewriteRule  ^([-a-z0-9]+)/details\\.html$ details.html?dir=$1 [L]

You left me guessing at your third requirement but, if details is not in the DocumentRoot, add the correct directory in the redirection. Also, .html files can’t process query strings so I’m guessing that you have an Apache directive to process .html files as .php scripts. If not, you may want to change the RewriteRule’s redirection from details.html to details.php.

Did that help?

Regards,

DK

Hi David,

wow more wonderful code…thank you :slight_smile: but not wanting to add to your mourning … not yet redirecting :frowning:

ok here is my complete .htacces code from www.trade-th.com (and it is a monster!) I am sure this will shine light onto the situation :slight_smile:

#
#  
# Trade-th.com
# 
# (c) 2011 Trade-th.com
#
#
        
<IfModule mod_deflate.c>
# DEFLATE by type - html, text, css, xml
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml

# DEFLATE by type - javascript
AddOutputFilterByType DEFLATE application/x-javascript application/javascript text/javascript text/x-js text/x-javascript

# DEFLATE by extension
AddOutputFilter DEFLATE js css htm html xml
</IfModule>


## Uncomment this if FollowSymLinks is not already enabled on your server
#Options +FollowSymLinks

## Use mod rewrite
## Comment the line below if RewriteEngine not already enabled on your server
RewriteEngine On

## Uncomment the line below and change the path if your script is installed
## in a different path than the root folder of your domain
        
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\\.trade-th\\.com [NC]
RewriteRule ^(.*)$ http://trade-th.com/$1 [L,R=301]

RewriteEngine on
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index\\.html
RewriteRule ^(.*)index.html$ http://www.trade-th.com/$1 [R=301,L] RewriteCond %{THE_REQUEST} ^.*/index\\.php
RewriteRule ^(.*)index.php$ http://www.trade-th.com/$1 [R=301,L]

RewriteBase /

RewriteRule ^index.html index.php [nc]
RewriteRule ^recent_ads.html recent_ads.php [nc]
RewriteRule ^register.html register.php [nc]
RewriteRule ^pre-register.html pre-register.php [nc]
RewriteRule ^login.html login.php [nc]
RewriteRule ^logout.html logout.php [nc]
RewriteRule ^favorites.html favorites.php [nc]
RewriteRule ^contact.html contact.php [nc]
RewriteRule ^listings.html listings.php [nc]
RewriteRule ^pre-submit.html pre-submit.php [nc]
RewriteRule ^([0-9]+)-([^\\/]+)?/content.html$ content.php?id=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\\/]+)?/index.html$ index.php?category=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\\/]+)?/details.html$ details.php?id=$1 [nc,qsa]
RewriteRule ^([^\\/]+)/([^\\/]+)/([^\\/]+)/recent_ads.html$ recent_ads.php?page=$1&order=$2&order_way=$3 [nc,qsa]
RewriteRule ^([0-9]+)-([^\\/]+)?/user_listings.html$ user_listings.php?id=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\\/]+)?/([^\\/]+)/([^\\/]+)/([^\\/]+)/user_listings.html$ user_listings.php?id=$1&page=$3&order=$4&order_way=$5 [nc,qsa]
RewriteRule ^([^\\/]+)/([^\\/]+)/([^\\/]+)/favorites.html$ favorites.php?page=$1&order=$2&order_way=$3 [nc,qsa]
RewriteRule ^([0-9]+)-([^\\/]+)?/store.html$ store.php?id=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\\/]+)?/([^\\/]+)/([^\\/]+)/([^\\/]+)/store.html$ store.php?id=$1&page=$3&order=$4&order_way=$5 [nc,qsa]

## Uncomment the following line when activating location subdomains
## Don't forget to replace yourdomainname.com with your own domain name !

#RewriteCond %{HTTP_HOST} !www.trade-th.com$ [NC]
#RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-_]+).trade-th.com [NC]
#RewriteRule (.*) %{SCRIPT_FILENAME}?crt_city=%2 [NC,QSA]

RewriteCond %{REQUEST_URI} ^(.*)(/listings.html)(.*)$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (.*) ./listings.php?$1

RewriteEngine On
RewriteCond %{HTTP_HOST} ^trade-th.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.trade-th.com$
RewriteRule (.*)$ http://www.classified-thailand.com/$1 [R=301,L]

# .htaccess in DocumentRoot of both trade-th.com and classified-thailand.com

# mod_rewrite code only - you can take care of your DirectoryIndex, Options -Indexes, ErrorDocument, etc.
RewriteEngine on

# force www.classified-thailand.com (#1 & #1a)
RewriteCond %{HTTP_HOST} !www\\.classified-thailand\\.com$ [NC]
RewriteRule .? http://www.classified-thailand.com%{REQUEST_URI} [R=301]

# Redirect 26-colloidal-silver-15-ppm-spray/details.html to 16-colloidal-silver-15-ppm/details.html (#2)
RewriteRule ^26-colloidal-silver-15-ppm-spray/details\\.html$ 16-colloidal-silver-15-ppm/details.html [R=301]

# The Missing Link! Redirect non-directory requests to details.html in DocumentRoot with dir={value of the non-directory}
RewriteCond %{REQUEST_FILENAME} ^([-a-z0-9]+)/details\\.html$
RewriteCond %{DOCUMENT_ROOT}/%1 !-d
# I don't think you need the / but I put it in here for you to test and report back, if you would be so kind
RewriteRule  ^([-a-z0-9]+)/details\\.html$ details.html?dir=$1 [L]

Hi Ray,

This is great (assuming that the two domains share the same DocumentRoot - I believe that you had confirmed somewhere above that they do; in cPanel, that’s called “Parked” domain).

I’ll go through your .htaccess and add notes as comments after saying that long .htaccess files are not a good thing AND you should test then REMOVE all your <IfModule> tests as they are wasteful. Remember, the .htaccess file is read and parsed MULTIPLE times for every FILE request!

#
#  
# Trade-th.com
#      AND Classified-Thailand.com
# 
# (c) 2011 Trade-th.com
#
#
        
[COLOR="#808080"]<IfModule mod_deflate.c>[/COLOR]
# DEFLATE by type - html, text, css, xml
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml

# DEFLATE by type - javascript
AddOutputFilterByType DEFLATE application/x-javascript application/javascript text/javascript text/x-js text/x-javascript

# DEFLATE by extension
AddOutputFilter DEFLATE js css htm html xml
[COLOR="#808080"]</IfModule>[/COLOR]


## Uncomment this if FollowSymLinks is not already enabled on your server
#Options +FollowSymLinks

## Use mod rewrite
## Comment the line below if RewriteEngine not already enabled on your server
RewriteEngine On

## Uncomment the line below and change the path if your script is installed
## in a different path than the root folder of your domain
        
RewriteEngine On
[COLOR="#808080"]RewriteBase /[/COLOR]
#      What's that supposed to do? It changes the location of files which are "moved" as a result of
#            Redirect statements so I'd recommend commenting this out

# Removes www from trade-th.com
#      If you're redirecting from trade-th to classified-thailand, WHY BOTHER?
RewriteCond %{HTTP_HOST} ^www\\.trade-th\\.com [NC]
RewriteRule ^(.*)$ http://trade-th.com/$1 [L,R=301]

[COLOR="#808080"]RewriteEngine on[/COLOR]
#      Only one statement is necessary to ensure mod_rewrite is not in the comment mode
[COLOR="#808080"]Options +FollowSymLinks[/COLOR]
#      Normally in httpd.conf - test then remove
RewriteCond %{THE_REQUEST} [COLOR="#FF0000"]^[/COLOR].*/index\\.html
#      {THE_REQUEST} starts with the HTTP version identification so you've got to get rid of the start anchor
RewriteRule ^(.*)index.html$ http://www.trade-th.com/$1 [R=301,L] RewriteCond %{THE_REQUEST} ^.*/index\\.php
RewriteRule ^(.*)index.php$ http://www.trade-th.com/$1 [R=301,L]
#      First, you've GOT to split the line with the RewriteCond.
#      Second, you don't need the RewriteCond statements if you simply use the + (one or more) metacharacter
#           rather than the * metacharacter (zero or more)
#      Third, you're making a circular redirection back to WWW.trade-th.com!?!

[COLOR="#808080"]RewriteBase /[/COLOR]
#      Second time when ZERO times is my recommendation

#      For the following RewriteRules, the No Case flag is quite inappropriate (unless coming from a WinDoze server).
#      Consider using the R=301 flag IF (and ONLY if) you want the redirection to be seen by the browser
#      Rather than a ridiculous list like this (especially with the pseudo-directories), try RewriteRule (.+)\\.html$ $1.php [L]
#          The point to this is to actually use the real power of mod_rewrite: Regular Expressions
#      Is there a reason for all the Query String Appended flags (are you expecting a pre-existing query string)?
RewriteRule ^index.html index.php [nc]
RewriteRule ^recent_ads.html recent_ads.php [nc]
RewriteRule ^register.html register.php [nc]
RewriteRule ^pre-register.html pre-register.php [nc]
RewriteRule ^login.html login.php [nc]
RewriteRule ^logout.html logout.php [nc]
RewriteRule ^favorites.html favorites.php [nc]
RewriteRule ^contact.html contact.php [nc]
RewriteRule ^listings.html listings.php [nc]
RewriteRule ^pre-submit.html pre-submit.php [nc]
RewriteRule ^([0-9]+)-([^\\/]+)?/content.html$ content.php?id=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\\/]+)?/index.html$ index.php?category=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\\/]+)?/details.html$ details.php?id=$1 [nc,qsa]
RewriteRule ^([^\\/]+)/([^\\/]+)/([^\\/]+)/recent_ads.html$ recent_ads.php?page=$1&order=$2&order_way=$3 [nc,qsa]
RewriteRule ^([0-9]+)-([^\\/]+)?/user_listings.html$ user_listings.php?id=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\\/]+)?/([^\\/]+)/([^\\/]+)/([^\\/]+)/user_listings.html$ user_listings.php?id=$1&page=$3&order=$4&order_way=$5 [nc,qsa]
RewriteRule ^([^\\/]+)/([^\\/]+)/([^\\/]+)/favorites.html$ favorites.php?page=$1&order=$2&order_way=$3 [nc,qsa]
RewriteRule ^([0-9]+)-([^\\/]+)?/store.html$ store.php?id=$1 [nc,qsa]
RewriteRule ^([0-9]+)-([^\\/]+)?/([^\\/]+)/([^\\/]+)/([^\\/]+)/store.html$ store.php?id=$1&page=$3&order=$4&order_way=$5 [nc,qsa]
#      For the rules with the pseudo-directories, remember that the browsers
#          will be looking for your image, css, js and other support files at the
#          WRONG directory level - see my signature's tutorial and look for the <BASE> tag solution.

## Uncomment the following line when activating location subdomains
## Don't forget to replace yourdomainname.com with your own domain name !

#RewriteCond %{HTTP_HOST} !www.trade-th.com$ [NC]
#RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-_]+).trade-th.com [NC]
#      Subdomains, too?
#RewriteRule (.*) %{SCRIPT_FILENAME}?crt_city=%2 [NC,QSA]
#      Is that an optional {SCRIPT_FILENAME} or are you trying to access the {QUERY_STRING}?

RewriteCond %{REQUEST_URI} ^(.*)(/listings.html)(.*)$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (.*) ./listings.php?$1
#      That seems like too much work to simply change listings.html to listings.php. Are there pseudo-directories to be concerned with?
#      Redirection to .listings.php with a query string?

[COLOR="#808080"]RewriteEngine On[/COLOR]
#      Ditto (again)
#      Redirect www.trade-th.com to www.classified-thailand.com. What about the non-www'd trade-th.com? Subdomains?
RewriteCond %{HTTP_HOST} ^trade-th.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.trade-th.com$
RewriteRule (.*)$ http://www.classified-thailand.com/$1 [R=301,L]

# .htaccess in DocumentRoot of both trade-th.com and classified-thailand.com

#      The following looks familiar BUT is grossly out of place!

# mod_rewrite code only - you can take care of your DirectoryIndex, Options -Indexes, ErrorDocument, etc.
[COLOR="#808080"]RewriteEngine on[/COLOR]
#      Ditto (again)

# force www.classified-thailand.com (#1 & #1a) -- SHOULD BE FIRST mod_rewrite (then forget about domains)
RewriteCond %{HTTP_HOST} !www\\.classified-thailand\\.com$ [NC]
RewriteRule .? http://www.classified-thailand.com%{REQUEST_URI} [R=301]

# Redirect 26-colloidal-silver-15-ppm-spray/details.html to 16-colloidal-silver-15-ppm/details.html (#2)
RewriteRule ^26-colloidal-silver-15-ppm-spray/details\\.html$ 16-colloidal-silver-15-ppm/details.html [R=301]

#      I'm still not sure whether you're using index.php or details.php (or {whatever}.php as your DirectoryIndex (file handler)
# The Missing Link! Redirect non-directory requests to details.html in DocumentRoot with dir={value of the non-directory}
RewriteCond %{REQUEST_FILENAME} ^([-a-z0-9]+)/details\\.html$
RewriteCond %{DOCUMENT_ROOT}/%1 !-d
# I don't think you need the / but I put it in here for you to test and report back, if you would be so kind
RewriteRule  ^([-a-z0-9]+)/details\\.html$ details.html?dir=$1 [L]

Ray, I tried to be rather pedantic in my comments but, despite the large number of comments, it seems as if you have a semi-grasp of mod_rewrite. PM with specific questions.

Regards,

DK