SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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-comm...2/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.

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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):

    Code:
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello dklynn, thank you for your reply, and solution, much appreciated

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

    best wishes

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello dklynn, thank you for you offer of help

    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

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

    many thanks,

    Ray

  6. #6
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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 [code]...[/code] tags as that preserves the code when quoting for a reply.

    Code:
    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]
    
    RewriteEngine on
    # This is only needed ONCE (to ensure you're not in "Comment Mode")
    Options +FollowSymLinks
    # 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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  8. #8
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello David, I see you are in Auckland, my home city, now I am a Kiwi in Bangkok

    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

  9. #9
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  10. #10
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello David,

    Your help again please.

    I would like this:

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

    Code:
    http://www.classified-thailand.com/16-colloidal-silver-15-ppm/details.html
    I tried this........but nope !

    Code:
    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:

    Code:
    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

  11. #11
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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:

    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\.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

    Code:
    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

    Code:
    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
      1. General applicability items (Domain Redirections, etc.)
      2. General applicability items (e.g., replace -'s with _'s, .html with .php, etc)
      3. RewriteRule sets (from most specific to most general)
        Be sure to use RewriteCond statements to skip the already performed redirections!
        This is generally the case with WP redirections where EVERYTHING (not a file/directory) is redirected to index.php.


    I hope that both made sense and helped.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  12. #12
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi David,

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

    Ok so I pasted your code:

    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:

    Code:
    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:
    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-sil...y/details.html shows: This listing does not exist!

    your help appreciated

  13. #13
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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

    2. Change one subdirectory to another

    and, the "Missing Link" is to

    3. 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).

    Code:
    # .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]
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  14. #14
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi David,

    wow more wonderful code...........thank you but not wanting to add to your mourning .............. not yet redirecting

    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

    Code:
    #
    #  
    # 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]

  15. #15
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,671
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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!

    Code:
    #
    #  
    # Trade-th.com
    #      AND Classified-Thailand.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 /
    #      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]
    
    RewriteEngine on
    #      Only one statement is necessary to ensure mod_rewrite is not in the comment mode
    Options +FollowSymLinks
    #      Normally in httpd.conf - test then remove
    RewriteCond %{THE_REQUEST} ^.*/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!?!
    
    RewriteBase /
    #      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?
    
    RewriteEngine On
    #      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.
    RewriteEngine on
    #      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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •