The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WWW redirect doesn't apply with filename

Discussion in 'Bind / DNS / Nameserver Issues' started by 123bear, May 13, 2015.

  1. 123bear

    123bear Member

    Joined:
    Apr 24, 2015
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Israel
    cPanel Access Level:
    Website Owner
  2. LostNerd

    LostNerd Well-Known Member

    Joined:
    Mar 12, 2014
    Messages:
    258
    Likes Received:
    11
    Trophy Points:
    18
    Location:
    Hastings, East Sussex, UK
    cPanel Access Level:
    Root Administrator
    Twitter:
    1. In cPanel, make sure your redirect is set up as a "Wild Card Redirect" if you want to redirect the domain but also the filename.

    2. Code issues/requests are better on a site such as StackOverflow.
     
  3. 123bear

    123bear Member

    Joined:
    Apr 24, 2015
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Israel
    cPanel Access Level:
    Website Owner
    I can NOT use Wild Card Redirect; because I get 'endless redirecting': "the server proccess this request in a way it will never be completed", or something similar.
    Do you need the .htaccess file?
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    Do you already have custom Mod_Rewrite rules associated with a script in your .htaccess file? Have you tried setting up individual redirects for specific file names?

    Thank you.
     
  5. 123bear

    123bear Member

    Joined:
    Apr 24, 2015
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Israel
    cPanel Access Level:
    Website Owner
    "custom Mod_Rewrite rules associated with a script in your .htaccess file?"
    Please elaborate...


    individual redirects for specific file names is too much trouble.

    Main .htaccess , before public_html

    <IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    <IfModule mod_setenvif.c>
    # Netscape 4.x has some problems...
    BrowserMatch ^Mozilla/4 gzip-only-text/html

    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip

    # MSIE masquerades as Netscape, but it is fine
    # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
    # the above regex won't work. You can use the following
    # workaround to get the desired effect:
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

    # Don't compress images
    SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    </IfModule>

    <IfModule mod_headers.c>
    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary
    </IfModule>
    </IfModule>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
    RewriteCond %{REQUEST_URI} ^/directory/(.*)$
    RewriteRule ^(.*)$ - [L,R=404]
    # 1 YEAR
    ExpiresActive On
    <FilesMatch "\.(otf|ico|pdf|flv)$">
    Header set Cache-Control "max-age=29030400, public"
    ExpiresDefault "access plus 1 years"
    Header unset Last-Modified
    Header unset ETag
    SetOutputFilter DEFLATE
    </FilesMatch>
    # 1 MONTHS
    <FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=2629000, public"
    ExpiresDefault "access plus 1 month"
    SetOutputFilter DEFLATE
    </FilesMatch>
    <FilesMatch "\.(xml|txt|css|js|html|htm|ph)$">
    Header set Cache-Control "max-age=2629000, public"
    ExpiresDefault "access plus 1 week"
    SetOutputFilter DEFLATE
    </FilesMatch>

    ###

    .htaccess Inside public_html

    RewriteEngine on
    # compress text, html, javascript, css, xml:
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/directory/(.*)$
    RewriteCond %{HTTP_REFERER} !^http://domain.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://domain.com$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://domain.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://domain.com$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://sub.domain.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://sub.domain.com$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.domain.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.domain.com$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.sub.domain.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.sub.domain.com$ [NC]
    RewriteRule .*\.(jpg|jpeg|gif|png|bmp|css)$ - [F,NC]
    # 1 YEAR
    ExpiresActive On
    <FilesMatch "\.(otf|ico|pdf|flv)$">
    Header set Cache-Control "max-age=29030400, public"
    ExpiresDefault "access plus 1 years"
    Header unset Last-Modified
    Header unset ETag
    SetOutputFilter DEFLATE
    </FilesMatch>
    # 1 MONTHS
    <FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=2629000, public"
    ExpiresDefault "access plus 1 month"
    SetOutputFilter DEFLATE
    </FilesMatch>
    <FilesMatch "\.(xml|txt|css|js|html|htm|ph)$">
    Header set Cache-Control "max-age=2629000, public"
    ExpiresDefault "access plus 1 week"
    SetOutputFilter DEFLATE
    </FilesMatch>
    RewriteCond %{HTTP_HOST} ^www\.domain\.com$
    RewriteRule ^/?$ "http\:\/\/domain\.com\/" [R=301,L]

    What is wrong?
     
    #5 123bear, May 13, 2015
    Last edited: May 13, 2015
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    Please keep in mind that custom redirect rules are not supported. We're happy to help as much as possible, but we can't write custom Mod_Rewrite rules for you. Have you tried backing up the existing rules, and adding the new rules to see if that's where the issue is? This third-party URL might help regarding new rules:

    http://stackoverflow.com/questions/1945568/htaccess-redirect-all-pages-to-new-domain

    Thank you.
     
  7. 123bear

    123bear Member

    Joined:
    Apr 24, 2015
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Israel
    cPanel Access Level:
    Website Owner
    I remember it used to work flawlessly. Would it help if I'll delete the .htaccess that inside the public_html directory? (or vice versa?)
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    You can try renaming the .htaccess file instead of deleting it so that it's disabled and backed up at the same time. Then, add the custom rules to a new .htaccess file.

    Thank you.
     
  9. 123bear

    123bear Member

    Joined:
    Apr 24, 2015
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Israel
    cPanel Access Level:
    Website Owner
    It works well now: probably a collisions between the two files.
    Immediately upon renaming original .htaccess; cPanel AUTOMATICALLY creates a new file with 100% correct settings.
     
  10. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    I am happy to see that resolved the issue. You could try manually inserting the custom rules one at a time if you want to see which particular one is at fault.

    Thank you.
     
Loading...

Share This Page