我試圖壓制目錄上的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>
1.'REQUEST_URI'包含正斜槓,所以'%{REQUEST_URI}!^ directory/* $'永遠不會匹配。 2. RewriteBase /對htaccess路徑很敏感,所以需要澄清。 3.關於rewritecond w/o下面的重寫代碼請閱讀以下內容。 – Deadooshka
「當我進入'/ directory/file.php'時,它會將我路由到'/ file.php'」 - 這是什麼意思?你是否在外部重定向(即URL更改)?或者您是否看到文檔根目錄中的文件內容?你的'.htaccess'文件中沒有任何內容可以做到這一點?對'/ directory/file.php'的請求將被內部路由到'/index.php?_route_ = directory/file.php'(但只有當該文件不存在時) - 至少根據您發佈的指令。你有其他的'.htaccess'文件嗎?服務器配置中的任何指令? – MrWhite
@ w3dk,獲取404錯誤(無法找到文件),但URL從/directory/file.php更改爲/file.php。但是提供的頁面沒有找到頁面 –