htaccess redirect help

Discussion in 'General' started by atomicmak, Sep 12, 2011.

  1. atomicmak

    atomicmak New Member

    need to redirect url from http://mydomain.tld to http://www.mydomain.tld

    i have wrote
    RewriteCond %{HTTP_HOST} ^wildart.in [NC]
    RewriteRule ^(.*)$ http://www.wildart.in/$1 [R=301,L]

    in my htaccess and still it cant redirect

    i am using hawkhost shared hosting.

    please help.
  2. NiteWave

    NiteWave Administrator

    the grammar looks ok.
    but http://wildart.in is served by cloudflare-nginx ? not litespeed
  3. atomicmak

    atomicmak New Member

    well yeah i use cloudflare service. does it make any differ as i thought it would just be a caching server for images.
  4. atomicmak

    atomicmak New Member

    here is the entire htaccess as i have many other rules which are working though i still using cloudflare.

    ====================

    # htaccess file version 1.4.1;
    # When Zenphoto requires changes to the rewrite rules:
    # First make a copy of this file as 'oldhtaccess' in the zp-core folder so setup can test for unmodified files
    # Update the above and the define in setup.php


    <IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteBase /

    RewriteRule ^admin/?$ zp-core/admin.php [R,L]

    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^albums/?(.+/?)?$ $1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [L]

    ##### put no rules before this line #######

    #######################
    #Rewrite rules for removed sitemap.php
    RewriteRule ^sitemap\.php index.php?sitemap [L,R=301]

    #Rewrite rules for removed RSS files
    RewriteCond %{QUERY_STRING} albumtitle=(.*)&albumname=(.*)&lang=".$lang
    RewriteRule ^rss\.php/?$ index.php?rss&albumtitle=%1&albumname=%2&lang=%3 [L,R=301]

    RewriteCond %{QUERY_STRING} albumtitle=(.*)&folder=(.*)&lang=(.*)
    RewriteRule ^rss\.php/?$ index.php?rss&albumtitle=%1&folder=%2&lang=%3 [L,R=301]

    RewriteCond %{QUERY_STRING} albumtitle=(.*)&albumname=(.*)&lang=(.*)
    RewriteRule ^rss\.php/?$ index.php?rss&albumtitle=%1&albumname=%2&lang=%3 [L,R=301]

    RewriteCond %{QUERY_STRING} folder=(.*)&lang=(.*)&albumsmode
    RewriteRule ^rss\.php/?$ index.php?rss&folder%1&lang=%2&albumsmode [L,R=301]

    RewriteCond %{QUERY_STRING} withimages&lang=(.*)
    RewriteRule ^rss-news\.php/?$ index.php?rss-news&withimages&lang=%1 [L,R=301]

    RewriteCond %{QUERY_STRING} id=(.*)&title=(.*)&type=(.*)&lang=(.*)
    RewriteRule ^rss-comments\.php/?$ index.php?rss-comments&id=%1&title=%2&type=%3&lang=%4 [L,R=301]

    RewriteCond %{QUERY_STRING} type=(.*)&lang=(.*)
    RewriteRule ^rss-comments\.php/?$ index.php?rss-comments&type=%1&lang=%2 [L,R=301]

    RewriteCond %{QUERY_STRING} lang=(.*)&albumsmode
    RewriteRule ^rss\.php/?$ index.php?rss&lang=%1&albumsmode [L,R=301]

    RewriteCond %{QUERY_STRING} lang=(.*)&category=(.*)
    RewriteRule ^rss-news\.php/?$ index.php?rss-news&lang=%1&category=%2 [L,R=301]

    RewriteCond %{QUERY_STRING} lang=(.*)
    RewriteRule ^rss\.php/?$ index.php?rss&lang=%1 [L,R=301]
    RewriteRule ^rss-news\.php/?$ index.php?rss-news&lang=%1 [L,R=301]
    #######################
    #rewrite rule for tinyURLs
    RewriteRule ^tiny/([0-9]+)/?$ index.php?p=$1&t [L,QSA]

    RewriteRule index\.php$ index.php [L,QSA]
    RewriteRule ^page/([0-9]+)/?$ index.php?page=$1 [L,QSA]
    RewriteRule ^page/([A-Za-z0-9_\-]+)/?$ index.php?p=$1 [L,QSA]
    RewriteRule ^page/([A-Za-z0-9_\-]+)/([0-9]+)/?$ index.php?p=$1&page=$2 [L,QSA]
    RewriteRule ^(.*)/page/([0-9]+)/?$ index.php?album=$1&page=$2 [L,QSA]
    RewriteRule ^(.*)/page/([A-Za-z0-9_\-]+)/?$ index.php?album=$1&p=$2 [L,QSA]

    #### Rewrite rule addition for search
    RewriteRule ^page/search/fields([0-9]+)/(.*)/([0-9]+)/?$ index.php?p=search&searchfields=$1&words=$2&page=$3 [L,QSA]
    RewriteRule ^page/search/fields([0-9]+)/(.*)/?$ index.php?p=search&searchfields=$1&words=$2 [L,QSA]
    RewriteRule ^page/search/archive/(.*)/([0-9]+)/?$ index.php?p=search&date=$1&page=$2 [L,QSA]
    RewriteRule ^page/search/archive/(.*)/?$ index.php?p=search&date=$1 [L,QSA]
    RewriteRule ^page/search/tags/(.*)/([0-9]+)/?$ index.php?p=search&searchfields=tags&words=$1&page=$2 [L,QSA]
    RewriteRule ^page/search/tags/(.*)/?$ index.php?p=search&searchfields=tags&words=$1 [L,QSA]
    RewriteRule ^page/search/(.*)/([0-9]+)/?$ index.php?p=search&words=$1&page=$2 [L,QSA]
    RewriteRule ^page/search/(.*)/?$ index.php?p=search&words=$1 [L,QSA]
    #### Rewrite additions for zenpage
    RewriteRule ^pages/?$ index.php?p=pages [L,QSA]
    RewriteRule ^pages/(.*)/?$ index.php?p=pages&title=$1 [L,QSA]
    RewriteRule ^news/?$ index.php?p=news [L,QSA]
    RewriteRule ^news/([0-9]+)/?$ index.php?p=news&page=$1 [L,QSA]
    RewriteRule ^news/category/(.*)/([0-9]+)/?$ index.php?p=news&category=$1&page=$2 [L,QSA]
    RewriteRule ^news/category/(.*)/?$ index.php?p=news&category=$1 [L,QSA]
    RewriteRule ^news/archive/(.*)/([0-9]+)/?$ index.php?p=news&date=$1&page=$2 [L,QSA]
    RewriteRule ^news/archive/(.*)/?$ index.php?p=news&date=$1 [L,QSA]
    RewriteRule ^news/(.*)/?$ index.php?p=news&title=$1 [L,QSA]
    ####
    RewriteRule ^(.*)/image/(thumb|[0-9]{1,4})/([^/\\]+)$ zp-core/i.php?a=$1&i=$3&s=$2 [L,QSA]
    RewriteRule ^(.*)/image/([^/\\]+)$ zp-core/i.php?a=$1&i=$2 [L,QSA]
    RewriteRule ^(.*)/album/(thumb|[0-9]{1,4})/([^/\\]+)$ zp-core/i.php?a=$1&i=$3&s=$2&album=true [L,QSA]
    ####

    # Catch-all - everything else gets handled in PHP for compatibility.
    RewriteRule ^(.*)/?$ index.php?album=$1 [L,QSA]

    #WWW redirect

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

    </IfModule>AddHandler application/x-httpd-php53 php

    ==================================
  5. atomicmak

    atomicmak New Member

  6. NiteWave

    NiteWave Administrator

    got it -- move the 2 lines to the very beginning, should work fine.
  7. atomicmak

    atomicmak New Member

    you mean after RewriteEngine On ?
  8. NiteWave

    NiteWave Administrator

    yes. the order of rules is important.
  9. atomicmak

    atomicmak New Member

    i did like this but it still not working

    <IfModule mod_rewrite.c>
    RewriteEngine On
    #WWW redirect

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

    RewriteBase /

    RewriteRule ^admin/?$ zp-core/admin.php [R,L]

    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^albums/?(.+/?)?$ $1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [L]

    ##### put no rules before this line #######
  10. NiteWave

    NiteWave Administrator

    should remove a "/".
    try:
    RewriteCond %{HTTP_HOST} !^www\.wildart\.in$
    RewriteRule ^(.*)$ http://www.wildart.in/$1 [R=301,L]
  11. atomicmak

    atomicmak New Member

    thanks a ton it worked.

    now to the 2nd point i mention would appreciate if you can help me out redirecting the caps to small letters conversion in url's.
  12. NiteWave

    NiteWave Administrator

    try:

    RewriteRule Gulls/Laughing_gull gulls/laughing_gull [R=301,L]
    RewriteRule Gulls gulls [R=301,L]
  13. atomicmak

    atomicmak New Member

    well its not the only url

    what i was trying to convey is i have more than 300+ such caps letter url which i want to convert to small letters.

    in a short i want to convert caps to small letter in url through Rewrite Rule
  14. NiteWave

    NiteWave Administrator

    then try RewriteMap
  15. atomicmak

    atomicmak New Member

    tried this

    <IfModule mod_rewrite.c>
    RewriteEngine On

    #WWW redirect
    RewriteCond %{HTTP_HOST} !^www\.wildart\.in$
    RewriteRule ^(.*)$ http://www.wildart.in/$1 [R=301,L]

    #Force lowercase urls
    RewriteMap lc int:tolower
    RewriteCond %{REQUEST_URI} [A-Z]
    RewriteRule (.*) ${lc:$1} [R=301,L]

    --------
    didnt worked
    anything wrong ?
  16. atomicmak

    atomicmak New Member

    i am on shared hosting and i was reading forums saying

    RewriteMap lc int:tolower

    has to go in httpd.conf and i am surprise if i am allowed to do so..
  17. NiteWave

    NiteWave Administrator

  18. atomicmak

    atomicmak New Member

    oh okay. will try to talk to hawkhost people and find if they can help to resolve this ..

    thanks a ton again for some prompt help
  19. thuyend

    thuyend New Member

    I have similar rewrite issue.

    1) installing phpMyFAQ on litespeed
    2) i tried to add .htaccess on the directory /usr/local/lsws/DEFAULT/html
    htaccess looks like

    RewriteEngine On
    RewriteBase /phpMyFAQ/phpmyfaq-2.6.17/
    RewriteRule ^(.*)$ index.php?action=login [R=301,L]

    3) getting error 404

    Content len: 39, Request line: 'POST /phpMyFAQ/phpmyfaq-2.6.17/?action=login HTTP/1.1'
    Cookie len: 196, pmf_sid=300; FAIL_REDIRECT_URL=http%3A//soc-nms-01%3A8080/; pmf_auth=7f2b3f910c2b3ccacb0b3d168f8c82f8; LSWSWEBUI=0b1e2d4b0b57815a9b21d6f6df9394d4; lsws_uid=WhorRzeqL44%3D; lsws_pass=IMD5gb8hAH0%3D
    Find context with URI: [/], location: [/usr/local/lsws/DEFAULT/html/]
    [REWRITE] Rewrite engine is not enabled for context '/'
    Index file is not available in [/usr/local/lsws/DEFAULT/html/phpMyFAQ/phpmyfaq-2.6.17/]

    Please help.
  20. NiteWave

    NiteWave Administrator

    looks like .htaccess not work at all.
    please check settings of
    Server->General->Allow Override

Share This Page