mod_rewrite:url重写和重定向

时间:2016-10-19 08:53:35

标签: .htaccess mod-rewrite url-rewriting

我有以下网址:

http://example.com/pages/cms/impressum.php

并希望获得这样的网址:

http://example.com/impressum

我的重写规则是:

RewriteEngine on 
RewriteBase /
RewriteRule ^impressum$ /pages/cms/impressum.php [R,L]

问题是,我可以通过两种方式打开网址。我想从/pages/cms/impressum.php转发到/ impressum。如果我使用[R = 301],我不想要的第二个URL工作。我想扭转这条规则。

1 个答案:

答案 0 :(得分:1)

使用:

  def create_for_request    
    @request = Request.find(params[:request_id])    
    if @request          
      @image = Image.new(image_params)
      add_file_params(@image)
      @image.request = @request
      if @image.save       
        redirect_to request_path(@request)
      end     
    else
     #TODO show error no such request 
    end
  end