htaccess只允许URL中的特定单词

时间:2016-08-10 07:16:55

标签: apache .htaccess redirect mod-rewrite

我搜索了整个堆栈溢出但无法弄清楚这一点。

我希望htaccess只允许URL中的特定单词和异常。

例如:除非URL中有&,否则所有不包含以下单词的网址:(大,红,暗)都会返回404错误。

的示例:

e.g1:

http://www.example.com/7big6556/允许

e.g2:

http://www.example.com/8green65533返回404

e.g3:

http://www.example.com/hi-green&nice允许

2 个答案:

答案 0 :(得分:0)

这应该有效

newMeterList

答案 1 :(得分:0)

我来解决方案:

class IncomingController < ApplicationController
  skip_before_action :verify_authenticity_token, only: [:create]
  skip_before_action :authenticate_user!, only: [:create]
  def create
    # Find the user
     user = User.find_by(email: params[:sender])

     # Find the topic
     topic = Topic.find_by(title: params[:subject])

     # Assign the url to a variable after retreiving it from
     url = params["body-plain"]

     # If the user is nil, create and save a new user
     if user.nil?
       user = User.new(email: params[:sender], password: "password")
       user.save!
     end

     # If the topic is nil, create and save a new topic
      if topic.nil?
        topic = Topic.new(title: params[:subject], user: user)

        topic.save!
      end

      bookmark = topic.bookmarks.build(user: user, url: url, description: "bookmark for #{url}")

      bookmark.save!

    # Assuming all went well.
    head 200
  end
end