我一直試圖讓這個權利現在1或2個小時,尋找類似的問題,並嘗試解決方案。這可能是答案真的很明顯的問題之一。.htaccess重定向404錯誤
我試圖重定向大家誰正在訪問domain.com/title/ 任何和domain.com/title/ anotherpage PHP腳本,但它給我一個404錯誤時我嘗試訪問該頁面。
我在我的htaccess文件使用此代碼:
RewriteEngine on
RewriteRule ^/plugins/(.*)$ /yourscript.php?plugin=$1 [L]
這裏是我的.htaccess文件的完整副本。
ErrorDocument 404 /error/404.php
#Prevent full listing of files
Options -Indexes
#Redirect plugins
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/plugins/(.*)$ /foobar.php?plugin=$1 [NC,L]
</IfModule>
#Hide .php extension
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
</IfModule>
#compress
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
我已經嘗試將foobar.php腳本放在根文件夾和文件夾名稱插件中。
非常感謝您的幫助。
你得到的錯誤信息是什麼?一個標準的404或類似「另外,嘗試使用ErrorDocument時遇到404 Not Found錯誤」?還要注意,如果我沒有弄錯,'ErrorDocument 404/error/404.php'將指向'domain.com/error/404.php'(這是你的意圖嗎?)。還請嘗試通過(暫時)刪除您的htaccess中不相關的行來找出錯誤。 – Spooky 2012-07-25 21:59:09
@Spooky我得到一個正常的404錯誤。否「另外...」。 ErrorDocument的位置是打算的,並顯示我的自定義錯誤頁罰款。我也試過我的代碼的第一個片段,但它仍然給我錯誤。 – Mastergalen 2012-07-25 22:05:46
「顯示我的自定義錯誤頁面」 - 然後...我想我不理解你的問題/目標是什麼。如果這與'RewriteRule'有關,那麼我就會退縮,因爲我不知道。 – Spooky 2012-07-25 22:11:10