PHP Question

When I open PDF with link without www I got redirected to parent folder

Basically I got

When I open it i got redirected to parent folder of xdocs (root) and I can't view the file. If I open the link with www ( ) I can view the PDF normally.

This is my htaccess:

Options +Indexes +FollowSymLinks -MultiViews

RewriteEngine on
rewritecond %{http_host} ^ [nc]
rewriterule ^(.*)$$1 [r=301,nc]

# BEGIN products Rewrite
RewriteRule ^(kadmin)(/.*)?$ - [L]
RewriteRule ^(kadmin2)(/.*)?$ - [L]
RewriteRule ^(polycomp)(/.*)?$ - [L]
RewriteRule ^(.*)-cat([0-9]+) categories.php?cid=$2 [L,NC]
RewriteRule ^([A-Za-z0-9-_]+)/?$ products.php?pid=$1 [L]

# END products Rewrite
<IfModule mod_negotiation.c>
ErrorDocument 404 /404.php

<IfModule mod_geoip.c>
GeoIPEnable On

<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType image/x-ico "access plus 1 year"
ExpiresByType image/jpg "access plus 14 days"
ExpiresByType image/jpeg "access plus 14 days"
ExpiresByType image/gif "access plus 14 days"
ExpiresByType image/png "access plus 14 days"
ExpiresByType text/css "access plus 14 days"

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
AddOutputFilterByType DEFLATE img/svg+xml application/xhtml+xml application/xml
AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-otf
AddOutputFilterByType DEFLATE font/truetype font/opentype

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^index\.php$ / [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


The problem is with your redirect destination as it redirects all non-www requests to root

If you want to redirect non-www to requests to subfolder, change your last rule to this :

RewriteEngine on
            rewritecond %{http_host} ^ [nc]
            rewriterule ^(.*)$$1 [r=301,nc,l]