我正在处理托管在共享服务器上的rails应用程序。该应用程序位于子域:database.my_domain.org。我在设置时遇到了一些重写问题,详见本文:Extra directory prepended to my routes in production
现在我有一个可能相关但最终不同的问题。每当用户尝试在应用程序中编辑或创建对象时,他们就会得到一个"您正在寻找的页面不存在"错误。我可以在日志中看到出现了什么问题:应用程序启动对一个地址的请求,但它作为对不同地址的请求执行:
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
有一天,当没有人在使用应用程序时,这开始出乎意料。我已经将我的rails代码回滚到以前的版本,这没有解决问题,所以我相当确定rails代码不是问题。
我的子域(〜/ public_html / database)的根目录中的.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 :(得分:0)
除非您的子目录中有不同的规则,否则它们会继承到子目录。默认情况下,重写引擎处于关闭状态,因此将其关闭并不会更改任何内容。相反,您需要将其打开,但没有规则。
SetEnv GEM_HOME /home/user/ruby/gems
PassengerEnabled On
PassengerAppRoot /home/user/rails_apps/app_name/current/
RewriteEngine On
这告诉重写引擎您希望重写引擎处于启用状态并应用您在此目录上下文中的任何规则(无所有权),并且这有效地取代了您在父目录中的任何规则。