SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess doesn't redirect links

    I've been trying to set few redirections in cPanel, but they don't work, they simply don't redirect to anyhting. Hosting's support say that there might be some incompatibilities in htaccess files, but I've already tried to create new .htaccess files and apply desired rules via cPanel and it still didn't work. Here are redirections I'd like to have:

    http://www.domain1.com/shop/ and domain1.com/shop/ should redirect to http://www.domain2.com
    domain2.com should redirect to http://www.domain2.com (wildcard enabled because of SSL)
    Document root of http://www.domain1.com is public_html
    Document root of http://www.domain2.com is public_html/shop/

    Here is .htaccess from public_html
    Code:
    Options -Indexes
    Options +FollowSymLinks
    Options -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteRule ^teksti/([^./]+)([/]?)$ teksti.php?niceid=$1 [T=application/x-httpd-php,L]
    RewriteRule ^clanki/([^./]+)([/]?)$ clankishop.php?niceid=$1 [T=application/x-httpd-php,L]
    RewriteCond %{HTTP_HOST} .*www.domain2.com
    RewriteRule ^$ sportna_prehrana.php [T=application/x-httpd-php,L]
    
    RewriteRule ^shop.php$ sportna_prehrana.php%{QUERY_STRING} [T=application/x-httpd-php,L,R=301]
    RewriteRule ^cart.php$ nakup.php%{QUERY_STRING} [T=application/x-httpd-php,L,R=301]
    
    RewriteRule ^pagefit/$ pagefit/pagefit.php
    RewriteRule ^forum/$ forum/index.php
    
    #Redirect permanent fitnes_wellness.php pagefit/
    
    #RewriteRule ^internet.html$ internet.php?%{QUERY_STRING} [T=application/x-httpd-php,L]
    #RewriteRule ^programska_oprema.html$ programska_oprema.php?%{QUERY_STRING} [T=application/x-httpd-php,L]
    #RewriteRule ^storitve.html$ teksti.php?act=storitve&%{QUERY_STRING} [T=application/x-httpd-php,L]
    #RewriteRule ^podjetje.html$ teksti.php?act=opodjetju&%{QUERY_STRING} [T=application/x-httpd-php,L]
    #RewriteRule ^pogoji.html$ teksti.php?act=pogoji&%{QUERY_STRING} [T=application/x-httpd-php,L]
    #RewriteRule ^privatnost.html$ teksti.php?act=privatnost&%{QUERY_STRING} [T=application/x-httpd-php,L]
    #RewriteRule ^shop.html$ shop.php?aktualno=1&%{QUERY_STRING} [T=application/x-httpd-php,L]
    #RewriteRule ^podjetje/([^./]+).html$ shop.php?nicepod=$1&%{QUERY_STRING} [T=application/x-httpd-php,L]
    #RewriteRule ^([^./]+).html$ shop.php?nicecat0=$1&%{QUERY_STRING} [T=application/x-httpd-php,L]
    #RewriteRule ^([^./]+)/a/([^./]+).html$ shop.php?nicecat0=$1&niceart=$2&%{QUERY_STRING} [T=application/x-httpd-php,L]
    #RewriteRule ^([^./]+)/([^./]+).html$ shop.php?nicecat0=$1&nicecat1=$2&%{QUERY_STRING} [T=application/x-httpd-php,L]
    #RewriteRule ^([^./]+)/([^./]+)/a/([^./]+).html$ shop.php?nicecat0=$1&nicecat1=$2&niceart=$3&%{QUERY_STRING} [T=application/x-httpd-php,L]
    #RewriteRule ^([^./]+)/([^./]+)/([^./]+).html$ shop.php?nicecat0=$1&nicecat1=$2&nicecat2=$3&%{QUERY_STRING} [T=application/x-httpd-php,L]
    #RewriteRule ^([^./]+)/([^./]+)/([^./]+)/a/([^./]+).html$ shop.php?nicecat0=$1&nicecat1=$2&nicecat2=$3&niceart=$4&%{QUERY_STRING} [T=application/x-httpd-php,L]
    ErrorDocument 404 /404.php
    #DirectoryIndex fitnes_wellness.php
    #DirectoryIndex sportna_prehrana.phpRewriteCond %{HTTP_HOST} ^domain1.com$ [OR]
    DirectoryIndex vstop.php
    
    RewriteCond %{HTTP_HOST} ^.*$
    RewriteRule ^fitnes_wellness.php$ "http\:\/\/www\.domain1\.com\/pagefit\/" [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^.*$
    RewriteRule ^fitnes_wellness.php/$ "http\:\/\/www\.domain1\.com\/pagefit\/" [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^.*$
    RewriteRule ^pagefit/urednik/$ "http\:\/\/www\.domain1\.com\/pagefit\/urednik\/index\.php" [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^.*$
    RewriteRule ^pagefit/podstrani/$ "http\:\/\/www\.domain1\.com\/pagefit\/podstrani\/index\.php" [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^.*$
    RewriteRule ^kontakti/$ "http\:\/\/www\.domain1\.com\/kontakti\/index\.php" [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^.*$
    RewriteRule ^sportno_drustvo\.php$ "http\:\/\/www\.domain1\.com\/sdpage\/" [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^domain2\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.domain2\.com$
    RewriteRule ^/?$ "shop\/" [R=301,L]
    
    RewriteCond %{HTTP_HOST} ^domain1\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.domain1\.com$
    RewriteRule ^shop\/?$ "http\:\/\/www\.domain2\.com\/" [R=301,L]

    Here is .htaccess from public_html/shop/
    Code:
    # 1.To use URL Alias you need to be running apache with mod_rewrite enabled. 
    
    # 2. In your opencart directory rename htaccess.txt to .htaccess.
    
    # For any support issues please visit: http://www.opencart.com
    
    Options +FollowSymlinks
    
    # Prevent Directoy listing 
    Options -Indexes
    
    # Prevent Direct Access to files
    <FilesMatch "\.(tpl|ini|log)">
     Order deny,allow
     Deny from all
    </FilesMatch>
    
    # SEO URL Settings
    RewriteEngine On
    DirectoryIndex index.php index.html site-down.php install.php
    # If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/ 
    RewriteBase /shop/
    RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
    RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
    RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
    RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
    
    ### Additional Settings that may need to be enabled for some servers 
    ### Uncomment the commands by removing the # sign in front of it.
    ### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.
    
    # 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
    # php_flag register_globals off
    
    # 2. If your cart has magic quotes enabled, This may work to disable it:
    # php_flag magic_quotes_gpc Off
    
    # 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
    # php_value upload_max_filesize 999M
    
    # 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
    # php_value post_max_size 999M
    
    # 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
    # php_value max_execution_time 200
    
    # 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
    # php_value max_input_time 200
    
    # 7. disable open_basedir limitations
    # php_admin_value open_basedir none
    RewriteCond %{HTTP_HOST} ^domain2.com$
    RewriteRule ^(.*)$ "http\:\/\/www\.domain2\.com\/$1" [R=301,L]
    Does anybody know where's the problem? Thanks!

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    kmeki,

    Repeatedly, you're attempting to match the query string in a RewriteRule. Because the RewriteRule can only access the {REQUEST_URI} string (to match with the regex), those RewriteRules will never match. Other than that, the .htaccess code would be very different so I didn't look any further.

    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    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
  •