Canonical url problem in a phpld directory, driving me nuts

Discussion in 'Apache' started by thudufushi, Jul 29, 2007.

  1. #1
    Hi,

    Can some bright spark help me with a problem. I have about 40 of the pages of a directory in Googles index on the non-www domain as well as with www. domain. I understand seo and use 301's regularly when a problem like this shows up but when I add the code to my htaccess file to send anything at non-www to www.domain it only works on my details pages but not any of the category or sub category pages, on these pages the non-www address just redirects to index.php instead of the page with www.

    Here is the code I added ( i have removed the domain)
    RewriteCond %{HTTP_HOST} ^domain.com [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

    I think the problem is the line above but I dont know how to fix it!

    Any ideas?
    Steve

    #################################################
    ## PHP Link Directory - Apache Server Settings ##
    #################################################

    # Protect files
    <Files ~ "^(.*)\.(inc|inc\.php|tpl|sql)$">
    Order deny,allow
    Deny from all
    </Files>

    # Protect directories
    <Files ~ "^(backup|files|images|include|lang|libs(/.+)?|temp(/.+)?|templates(/.+)?|javascripts(/.+)?)$">
    Order deny,allow
    Deny from all
    </Files>

    # Disable directory browsing
    Options -Indexes

    # Follow symbolic links in this directory
    Options +FollowSymLinks

    # Override PHP settings that cannot be changed at runtime
    # (If your server supports PHP settings via htaccess you can comment following two lines off)
    # php_value register_globals 0
    # php_value session.auto_start 0

    # Customized error messages
    # ( If you are running in a subfolder please add it, example: "directory/index.php?httpstatus=404" )
    ErrorDocument 404 index.php?httpstatus=404

    # Set the default handler
    DirectoryIndex index.php

    # URL rewrite rules
    <IfModule mod_rewrite.c>
    RewriteEngine On

    ## Details Link Page Rewrite##
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule (.*)detail/link-(.*).html$ detail.php [QSA,NC]

    ## Pagination Rewrite
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule (.*)page-(\d+)\.html$ $1/?p=$2 [PT,NC]

    ## Category redirect
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.php [QSA,L]
    RewriteCond %{HTTP_HOST} ^domain.com [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
    </IfModule>
     
    thudufushi, Jul 29, 2007 IP
  2. VimF

    VimF Well-Known Member

    Messages:
    307
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    118
    #2
    RewriteCond %{HTTP_HOST} ^domain\.com [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
     
    VimF, Jul 29, 2007 IP
  3. thudufushi

    thudufushi Well-Known Member

    Messages:
    1,145
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    155
    #3
    Hi

    Thanks for trying, entered your suggestion and it does the same thing, if i select a page and remove the www. and press refresh it redirects to domain/index.php
     
    thudufushi, Jul 29, 2007 IP
  4. VimF

    VimF Well-Known Member

    Messages:
    307
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    118
    #4
    Okay try again with this:

    <IfModule mod_rewrite.c>
    RewriteEngine On

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

    ## Details Link Page Rewrite##
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule (.*)detail/link-(.*).html$ detail.php [QSA,NC]

    ## Pagination Rewrite
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule (.*)page-(\d+)\.html$ $1/?p=$2 [PT,NC]

    ## Category redirect
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.php [QSA,L]
    </IfModule>
     
    VimF, Jul 29, 2007 IP
    thudufushi likes this.
  5. thudufushi

    thudufushi Well-Known Member

    Messages:
    1,145
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    155
    #5
    You are a superstar, many thanks, thats got it. Green rep coming your way.

    Cheers,
    Steve
     
    thudufushi, Jul 29, 2007 IP
  6. ev8321

    ev8321 Guest

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Superstar you are VimF .. Hats off to you. Worked perfectly.
    I am using phpld 3.3 if anyone else finds this post!
     
    ev8321, Nov 23, 2009 IP
  7. neerajcatura

    neerajcatura Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    can anybody help me in this...
    on my php link directory website.. urls are not coming acc. to SEO friendly.. although these are .html files bt not SEO friendly...
    in article title name is not coming in url.. and same with links please tell me how to solve this..
    -- I have already enable the SEO url- on from backend.. this is what i have in my .ht access file

    ---
    #################################################
    ## PHP Link Directory - Apache Server Settings ##
    #################################################


    # Prevent .htaccess and .htpasswd files from being viewed by web clients
    <Files "^\.ht">
    Order allow,deny
    Deny from all
    </Files>

    # Protect files
    <Files ~ "^(.*)\.(inc|inc\.php|tpl|sql)$">
    Order deny,allow
    Deny from all
    </Files>

    # Protect directories
    <Files ~ "^(backup|files|images|include|lang|libs(/.+)?|temp(/.+)?|templates(/.+)?|javascripts(/.+)?)$">
    Order deny,allow
    Deny from all
    </Files>

    # Disable directory browsing
    Options -Indexes

    # Follow symbolic links in this directory
    Options +FollowSymLinks

    # Override PHP settings that cannot be changed at runtime
    # (If your server supports PHP settings via htaccess you can comment following two lines off)
    # php_value register_globals 0
    # php_value session.auto_start 0

    # Customized error messages
    # ( If you are running in a subfolder please add it, example: "directory/index.php?httpstatus=404" )
    ErrorDocument 404 index.php?httpstatus=404

    # Set the default handler
    DirectoryIndex index.php

    # URL rewrite rules
    <IfModule mod_rewrite.c>
    RewriteEngine On


    #Make sure RewriteBase points to the directory where you installed phpLD.
    #Example: "/phpld" if your installation is in a "phpld" subdirectory.

    #RewriteBase /

    ##Latest Links Rewrite
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^latest-links\.htm[l]?$ index.php?list=latest [QSA,NC,L]

    ##Top Hits Rewrite
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^top-hits\.htm[l]?$ index.php?list=top [QSA,NC,L]

    ##Latest Articles Rewrite
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^latest-articles\.htm[l]?$ index.php?list=latestarticles [QSA,NC,L]

    ##Details Link Page Rewrite
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule (.*)detail/link-(.*)\.htm[l]?$ detail.php [QSA,NC]

    ##Article Page Rewrite
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule (.*)articles/article-(.*)\.htm[l]?$ article.php [QSA,NC]

    ##Author Page Rewrite
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule (.*)authors/author-(.*)\.htm[l]?$ author.php [QSA,NC]

    ##Pagination Rewrite
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule (.*)page-[0-9]+\.html$ index.php [QSA,NC,L]

    ##Pages redirect
    RewriteCond %{REQUEST_URI} !page-[0-9]+\.html?$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.+)\.html$ page.php?name=$1 [NC,QSA,L]

    ##Category redirect
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.php [QSA,L]
    </IfModule>

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule .* index.php [QSA,L]
    --
     
    neerajcatura, Jul 31, 2010 IP