2017-04-15 112 views
0

我試圖壓制目錄上的mod_write。目前當我去http://example.com/directory/file.php時,它會將我路由到http://example.com/file.php。我希望它只是提供那裏的file.php。我試着做.htaccess mod_write在目錄上壓制重寫

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

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] 

既不似乎工作。還有什麼我可以嘗試?

以下是完整的文件...

#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> 
+0

1.'REQUEST_URI'包含正斜槓,所以'%{REQUEST_URI}!^ directory/* $'永遠不會匹配。 2. RewriteBase /對htaccess路徑很敏感,所以需要澄清。 3.關於rewritecond w/o下面的重寫代碼請閱讀以下內容。 – Deadooshka

+0

「當我進入'/ directory/file.php'時,它會將我路由到'/ file.php'」 - 這是什麼意思?你是否在外部重定向(即URL更改)?或者您是否看到文檔根目錄中的文件內容?你的'.htaccess'文件中沒有任何內容可以做到這一點?對'/ directory/file.php'的請求將被內部路由到'/index.php?_route_ = directory/file.php'(但只有當該文件不存在時) - 至少根據您發佈的指令。你有其他的'.htaccess'文件嗎?服務器配置中的任何指令? – MrWhite

+0

@ w3dk,獲取404錯誤(無法找到文件),但URL從/directory/file.php更改爲/file.php。但是提供的頁面沒有找到頁面 –

回答

0

嘗試,而不是下面的REQUEST_FILENAME

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

,我發現了同樣的問題在我的網站之一。

0

我試圖在目錄上禁止mod_write。

要做到這一點,你可以創建一個.htaccess文件在該目錄中,只需啓用重寫引擎:

RewriteEngine On 

mod_rewrite的指令默認情況下不繼承,所以這個完全覆蓋在mod_rewrite的指令父母.htaccess文件。


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

這也應該工作,只要它被放置在您的.htaccess文件的開始。順便說一句,像^/directory/.*$這樣的模式與簡單的^/directory/相同。如果您使用的是Apache 2.4+,則可以使用END而不是L

RewriteCond %{REQUEST_URI} !pagespeed 

這似乎是一個流浪條件在你的mod_rewrite的規則到底!?如果在其後麪包含任何mod_rewrite指令(如文件中的任何地方),這將導致問題。

+0

我註釋掉了'RewriteCond%{REQUEST_URI}!pagespeed',但這沒有幫助。我也嘗試用'RewriteEngine On'在目錄中創建一個新的'.htaccess'文件...也沒有工作..... = **************(I'我真的很絕望.....謝謝你的幫助! –