www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Redirection problem in .htaccess

  1. #1
    Join Date
    May 2004
    Location
    FL
    Posts
    3,453

    resolved [RESOLVED] Redirection problem in .htaccess

    I have set-up an .htaccess file (listed below) for a newly designed website (the domain has been up for years). One of the errors I am receiving is when a visitor goes to the URL http://example.com/Newsletters/5765-2005.pdf they should be directed to http://example.com/newsletters/5765-2005.pdf (small "n" in "newsletters"). But they somehow are redirected to http://example.com/articles/letters/5765-2005.pdf

    The sub-directory "letters" does not exist, nor is it listed in the .htaccess file, unless it is shortening the "newsletters" directory and placing the "articles" directory in front of it.

    I have tried the page at http://web-sniffer.net/ and it says it's a 301 permanent move and gives the correct directory where it has moved, i.e., http://example.com/newsletters/5765-2005.pdf

    Any one have any ideas of what is going on?

    .htaccess file

    Code:
    AddHandler application/x-httpd-php54s .php
    AddHandler server-parsed .html
    AddHandler server-parsed .htm
    
    Options +SymLinksIfOwnerMatch
    RewriteEngine on
    RewriteBase /
    ServerSignature Off
    Options ExecCGI Includes IncludesNOEXEC SymLinksIfOwnerMatch -Indexes
    
    # backward compatibility ruleset for rewriting document.htm to document.php
    RewriteRule   ^(.*)\.htm$              $1      [C,E=WasHTML:yes]
    RewriteCond   %{REQUEST_FILENAME}.php -f
    RewriteRule   ^(.*)$ $1.php                   [S=1,R]
    RewriteCond   %{ENV:WasHTML}            ^yes$
    RewriteRule   ^(.*)$ $1.htm
    
    # Blocks access from libwww-perl user-agents and URLS which include the command "=http:"
    RewriteCond %{HTTP_USER_AGENT} libwww [NC,OR]
    RewriteCond %{QUERY_STRING} ^(.*)=http [NC]
    RewriteRule ^(.*)$ - [F,L]
    
    # Redirect www to non-www
    RewriteCond %{HTTP_HOST} ^www.example.com$  [NC]
    RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
    
    # Prevent hotlinking of images
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.org/.*$ [NC]
    RewriteRule \.(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]
    
    # Used for the errorpage.php file
    ErrorDocument 400 /errorpage.php
    ErrorDocument 401 /errorpage.php
    ErrorDocument 403 /errorpage.php
    ErrorDocument 404 /errorpage.php
    ErrorDocument 500 /errorpage.php
    
    # Caching
    # ExpiresActive On
    # ExpiresDefault A0
    <ifModule mod_headers.c>
    # 1 YEAR
    <filesMatch ".(ico|pdf|flv)$">
    Header set Cache-Control "max-age=29030400, public"
    </filesMatch>
    # 1 WEEK
    <filesMatch ".(jpg|jpeg|png|gif|swf|css|js)$">
    Header set Cache-Control "max-age=604800, public"
    </filesMatch>
    # 2 DAYS
    <filesMatch ".(xml|txt)$">
    Header set Cache-Control "max-age=172800, proxy-revalidate"
    </filesMatch>
    # 1 MIN
    <filesMatch ".(html|htm|php)$">
    Header set Cache-Control "max-age=60, private, proxy-revalidate"
    </filesMatch>
    </ifModule>
    <ifModule mod_expires.c>
    # any Expires Directives go here
    </ifModule>
    # End Caching
    
    # compress text, html, javascript, css, xml:
    FilterDeclare   COMPRESS
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/html
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/css
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/javascript
    FilterChain     COMPRESS
    FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no
    # <IfModule mod_deflate.c>
    # 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
    # </IfModule>
    
    # <Files 403.shtml>
    # order allow,deny
    # allow from all
    # </Files>
    
    <Files php.ini>
    Order allow,deny
    Deny from all
    </Files>
    
    RewriteRule ^Articles/?(.*)$ http://example.com/articles/$1 [R=301,L]
    RewriteRule ^Events/?(.*)$ http://example.com/events/$1 [R=301,L]
    RewriteRule ^News/?(.*)$ http://example.com/articles/$1 [R=301,L]
    RewriteRule ^Newsletters/?(.*)$ http://example.com/newsletters/$1 [R=301,L]
    Lee

    ""Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."" -- Sir Winston Churchill

  2. #2
    Join Date
    May 2004
    Location
    FL
    Posts
    3,453
    anyone?
    Lee

    ""Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."" -- Sir Winston Churchill

  3. #3
    Join Date
    May 2004
    Location
    FL
    Posts
    3,453
    For the record, it worked when these two lines were reversed:

    Code:
    RewriteRule ^News/?(.*)$ http://example.com/articles/$1 [R=301,L]
    RewriteRule ^Newsletters/?(.*)$ http://example.com/newsletters/$1 [R=301,L]
    e.g.,

    Code:
    RewriteRule ^Newsletters/?(.*)$ http://example.com/newsletters/$1 [R=301,L]
    RewriteRule ^News/?(.*)$ http://example.com/articles/$1 [R=301,L]
    Lee

    ""Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."" -- Sir Winston Churchill

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles