2014-10-07 61 views
1

我正在使用託管在共享服務器上的Rails應用程序。該應用程序位於子域:database.my_domain.org。當我設置它時,我有一些重寫問題,在這篇文章中詳細說明:Extra directory prepended to my routes in production如何判斷apache重寫規則是否適用於我的請求?

現在我有一個潛在的相關但最終不同的問題。無論用戶何時嘗試編輯或創建應用程序中的對象,都會收到「您正在查找的頁面不存在」錯誤。我可以什麼錯誤日誌中看到:在應用程序啓動的請求一個地址,但它是作爲一個不同的地址的請求執行:當沒有人正在上的應用程序

Started PUT "/individuals/4" for 72.93.46.141 at Tue Oct 07 10:54:37 -0400 2014 

ActionController::RoutingError (No route matches [PUT] "/4"): 
    actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 
    actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' 
    railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app' 
    railties (3.2.13) lib/rails/rack/logger.rb:16:in `call' 
    activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged' 
    railties (3.2.13) lib/rails/rack/logger.rb:16:in `call' 
    actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call' 
    rack (1.4.5) lib/rack/methodoverride.rb:21:in `call' 
    rack (1.4.5) lib/rack/runtime.rb:17:in `call' 
    activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call' 
    rack (1.4.5) lib/rack/lock.rb:15:in `call' 
    rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward' 
    rack-cache (1.2) lib/rack/cache/context.rb:143:in `pass' 
    rack-cache (1.2) lib/rack/cache/context.rb:155:in `invalidate' 
    rack-cache (1.2) lib/rack/cache/context.rb:71:in `call!' 
    rack-cache (1.2) lib/rack/cache/context.rb:51:in `call' 
    railties (3.2.13) lib/rails/engine.rb:479:in `call' 
    railties (3.2.13) lib/rails/application.rb:223:in `call' 
    railties (3.2.13) lib/rails/railtie/configurable.rb:30:in `send' 
    railties (3.2.13) lib/rails/railtie/configurable.rb:30:in `method_missing' 
    passenger (3.0.18) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request' 
    passenger (3.0.18) lib/phusion_passenger/abstract_request_handler.rb:516:in `accept_and_process_next_request' 
    passenger (3.0.18) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop' 
    passenger (3.0.18) lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler' 
    passenger (3.0.18) lib/phusion_passenger/rack/application_spawner.rb:171:in `send' 
    passenger (3.0.18) lib/phusion_passenger/rack/application_spawner.rb:171:in `handle_spawn_application' 
    passenger (3.0.18) lib/phusion_passenger/utils.rb:470:in `safe_fork' 
    passenger (3.0.18) lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application' 
    passenger (3.0.18) lib/phusion_passenger/abstract_server.rb:357:in `__send__' 
    passenger (3.0.18) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop' 
    passenger (3.0.18) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously' 
    passenger (3.0.18) lib/phusion_passenger/abstract_server.rb:180:in `start' 
    passenger (3.0.18) lib/phusion_passenger/rack/application_spawner.rb:129:in `start' 
    passenger (3.0.18) lib/phusion_passenger/spawn_manager.rb:253:in `spawn_rack_application' 
    passenger (3.0.18) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add' 
    passenger (3.0.18) lib/phusion_passenger/spawn_manager.rb:246:in `spawn_rack_application' 
    passenger (3.0.18) lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize' 
    passenger (3.0.18) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize' 
    passenger (3.0.18) lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application' 
    passenger (3.0.18) lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application' 
    passenger (3.0.18) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application' 
    passenger (3.0.18) lib/phusion_passenger/abstract_server.rb:357:in `__send__' 
    passenger (3.0.18) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop' 
    passenger (3.0.18) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously' 
    passenger (3.0.18) helper-scripts/passenger-spawn-server:99 

這開始意外1天。我已經將我的rails代碼回滾到以前的版本,但這並沒有解決問題,所以我相當肯定rails代碼不是問題。

在我的子域(〜/的public_html /數據庫)的根目錄下的.htaccess文件看起來是這樣的:

SetEnv GEM_HOME /home/user/ruby/gems 
PassengerEnabled On 
PassengerAppRoot /home/user/rails_apps/app_name/current/ 

RewriteEngine Off 

我看不出有任何的方式,這可能仍然可以重新寫我的網址。

另一方面,〜/ public_html(上一個目錄)中的.htaccess文件包含各種規則。我不認爲他們正在使用。我備份並刪除了該文件,問題仍在發生。這裏是〜/的public_html/.htaccess文件,如果有幫助:

Options +FollowSymLinks +ExecCGI 

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    # uncomment the following line, if you are having trouble 
    # getting no_script_name to work 
    #RewriteBase/

    # we skip all files with .something 
    #RewriteCond %{REQUEST_URI} \..+$ 
    #RewriteCond %{REQUEST_URI} !\.html$ 
    #RewriteRule .* - [L] 

#old links 
redirect 301 /shop /chocolate_shop 
redirect 301 /shop /chocolate_shop 
redirect 301 /pg/show/id/4 /chocolate_shop 

redirect 301 /pg/show/id/1 /our_philosophy 
redirect 301 /pg/show/id/2 /our_story 
redirect 301 /pg/show/id/3 /our_vision 

redirect 301 /pg/show/id/4 /chocolate_shop 
redirect 301 /pg/show/id/32 /chocolate_menu 
redirect 301 /pg/show/id/5 /family 
redirect 301 /pg/show/id/6 /garden 
redirect 301 /pg/show/id/28 /garden_what_we_grow 
redirect 301 /pg/show/id/23 /garden_a_typical_day 
redirect 301 /pg/show/id/7 /festival 
redirect 301 /pg/show/id/8 /catering 
redirect 301 /pg/show/id/27 /catering_menu 

#people pages 
redirect 301 /pg/show/id/11/person/1 /people?johndoe 
redirect 301 /pg/show/id/11/person/2 /people?janeplain 
redirect 301 /pg/show/id/11/person/4 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/5 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/8 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/9 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/11 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/19 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/20 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/21 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/22 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/23 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/24 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/26 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/27 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/28 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/29 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/30 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/31 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/34 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/42 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/43 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/44 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/45 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/46 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/47 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/48 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/50 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/51 /people?joeshmoe 
redirect 301 /pg/show/id/11/person/52 /people?joeshmoe 

redirect 301 /pg/show/id/11 /people 
redirect 301 /pg/show/id/12 /learning 
redirect 301 /pg/show/id/13 /events 

#updates pages 
redirect 301 /pg/show/id/36 /feed 
redirect 301 /pg/show/id/17 /news 

#give pages 
redirect 301 pg/show/id/14 /give 
redirect 301 pg/show/id/15 /volunteer 
redirect 301 pg/show/id/16 /goods 
redirect 301 pg/show/id/30 /volunteer_form 

#policy page 
redirect 301 /pg/show/id/34 /privacy 

#search page 
redirect 301 /pg/show/id/35 /search 

# Internally rewrite URLs requested with no filetype to php scripts 
# unless the requested URL resolves to an existing directory or file. 
RewriteCond %{REQUEST_URI} !(\.[^./]+)$ 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ /$1.shtml [L] 

    # we check if the .html version is here (caching) 
    #RewriteRule ^$ index.html [QSA] 
    #RewriteRule ^([^.]+)$ $1.html [QSA] 
    #RewriteCond %{REQUEST_FILENAME} !-f 

    # no, so we redirect to our front web controller 
    #RewriteRule ^(.*)$ index.php [QSA,L] 
</IfModule> 

RewriteCond %{HTTP_HOST} ^phillycatering\.com$ [OR] 
RewriteCond %{HTTP_HOST} ^www\.phillycatering\.com$ 
RewriteRule ^/?$ "http\:\/\/my_domain\.org\/chocolate_shop" [R=301,L] 

繼承的子目錄中的重寫規則?有什麼辦法可以告訴我的請求應用了哪些apache重寫規則?

回答

0

它們被繼承到子目錄,除非在子目錄中有不同的規則。默認情況下,重寫引擎處於關閉狀態,因此將其關閉不會改變任何內容。相反,你需要把它變成,但沒有規則。

SetEnv GEM_HOME /home/user/ruby/gems 
PassengerEnabled On 
PassengerAppRoot /home/user/rails_apps/app_name/current/ 

RewriteEngine On 

這告訴你要重寫引擎上,並在此目錄範圍內應用您有任何規則(這是無)重寫引擎,並能有效地將取代你的父目錄有什麼規則。

+0

謝謝Jon!這很有道理,但不幸的是它沒有改變任何東西。任何其他想法? – lucas 2014-10-07 16:39:53

+0

@lucas我唯一能想到的其他事情是在您的父htaccess文件的頂部添加一個'RewriteRule^database/- [L]'。 – 2014-10-07 16:45:30

+0

這是一個好主意。它並沒有改變任何東西,但我認爲至少可以消除規則可能從父htaccess文件繼承的可能性。 – lucas 2014-10-08 13:06:34