Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to make the following redirection (301) using .htaccess

*?page=1 redirects to *

(where * is a wildcard).

Basically, I just want to prevent anyone accessing a page with ?page=1 at the end of the URL, and instead direct them to the same url minus ?page=1.

Is there a quick way of doing this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.5k views
Welcome To Ask or Share your Answers For Others

1 Answer

This should do it:

RewriteEngine    On
RewriteCond      %{QUERY_STRING}    ^page=1$
RewriteRule      (.*)               $1?     [R=permanent]

Line by line:

  1. You turn on the rewriting functionality.
  2. You specify as a condition ("if statement") that the query string has to be exactly page=1 for the following rules to apply.
  3. Then you specify a rule that says substitute the entire path (.*) with itself ($1), but make the query string empty (?), and make the result a permanent redirect (301).

If you want the redirect to be temporary (302) then you can just remove the =permanent part. Moved Temporarily is the default for the R flag.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...