skip to Main Content

I’m trying to suppress mod_write on a directory. Currently when I go to http://example.com/directory/file.php, it routes me to http://example.com/file.php. I want it to simply serve up the file.php that is there. I’ve tried doing

RewriteCond %{REQUEST_URI} ^/directory/.*$ [NC]
RewriteRule . - [L]

and

RewriteCond %{REQUEST_URI} !^directory/*$ [NC]
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]

neither seems to work. Is there anything else I can try?

Here is the full file…

#php_value safe_mode off
<IfModule pagespeed_module>
  ModPagespeed off
</IfModule>

# 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

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/ 

##Header add Access-Control-Allow-Origin "*" 
RewriteBase /

RewriteRule ^image/data/(.*)$ /image/catalog/$1 [R=301,NC,L]
############First Mod 12/16 Only One Address Per Site#########

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]
RewriteCond %{REQUEST_URI} !pagespeed

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault A0
</IfModule>
# Set up caching on media files for 5 weeks
<FilesMatch ".(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A3024000
Header append Cache-Control "public"
</FilesMatch>

# Set up caching on media files for 5 weeks
<FilesMatch ".(gif|jpg|jpeg|png|swf)$">
ExpiresDefault A3024000
Header append Cache-Control "public"
</FilesMatch>

# Set up 1 day caching on commonly updated files
<FilesMatch ".(xml|txt|html|js|css)$">
ExpiresDefault A604800
Header append Cache-Control "proxy-revalidate"
</FilesMatch>

# Force no caching for dynamic files
<FilesMatch ".(php|cgi|pl|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>

<IfModule mod_headers.c>
  <FilesMatch ".(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>

 <IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript image/x-icon
    <filesMatch ".(css|js|x?html?|php|ico)$">
        SetOutputFilter DEFLATE
    </filesMatch> </ifModule>
<ifModule mod_headers.c>
    Header set Connection keep-alive
</ifModule>


<IfModule mod_filter.c>
    AddOutputFilterByType DEFLATE "application/atom+xml" 
                                  "application/javascript" 
                                  "application/json" 
                                  "application/ld+json" 
                                  "application/manifest+json" 
                                  "application/rdf+xml" 
                                  "application/rss+xml" 
                                  "application/schema+json" 
                                  "application/vnd.geo+json" 
                                  "application/vnd.ms-fontobject" 
                                  "application/x-font-ttf" 
                                  "application/x-javascript" 
                                  "application/x-web-app-manifest+json" 
                                  "application/xhtml+xml" 
                                  "application/xml" 
                                  "font/eot" 
                                  "font/opentype" 
                                  "image/bmp" 
                                  "image/svg+xml" 
                                  "image/vnd.microsoft.icon" 
                                  "image/x-icon" 
                                  "text/cache-manifest" 
                                  "text/css" 
                                  "text/html" 
                                  "text/javascript" 
                                  "text/plain" 
                                  "text/vcard" 
                                  "text/vnd.rim.location.xloc" 
                                  "text/vtt" 
                                  "text/x-component" 
                                  "text/x-cross-domain-policy" 
                                  "text/xml"

</IfModule>

2

Answers


  1. Try the following instead of REQUEST_FILENAME:

    RewriteCond %{SCRIPT_FILENAME} !-f [NC]
    RewriteCond %{SCRIPT_FILENAME} !-d [NC]
    

    I found the same problem on one of my sites.

    Login or Signup to reply.
  2. I’m trying to suppress mod_write on a directory.

    To do this, you can create a .htaccess file in that directory and simply enable the rewrite engine:

    RewriteEngine On
    

    mod_rewrite directives are not inherited by default, so this completely overrides the mod_rewrite directives in the parent .htaccess file.


    RewriteCond %{REQUEST_URI} ^/directory/.*$ [NC]
    RewriteRule . - [L]
    

    This should also work, providing it was placed at the start of your .htaccess file. Incidentally, a pattern like ^/directory/.*$ is the same as simply, ^/directory/. If you are on Apache 2.4+ then you can use the END flag instead of L.

    RewriteCond %{REQUEST_URI} !pagespeed
    

    This appears to be a stray condition at end of your mod_rewrite rules!? This will cause problems if you include any mod_rewrite directives after it (as in anywhere in the file).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search