简体   繁体   中英

Apache .htaccess folder redirect rule

I need to know how to create the folowing rules in the same .htaccess file:

  1. redirect from example.com/st to example.com
  2. redirect from example.com/[ANY STRING] to new-example.com/[ANY STRING]

The problem is that I need to send the query string as is.

Your question is not very clear but you can try this code in your .htaccess file:

Options +FollowSymLinks -MultiViews
RewriteEngine on

# your first requirement
RewriteRule ^st/?$ / [L]

# your second requirement; it will also append existing query string
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^ http://new-example.com%{REQUEST_URI} [L,R=301]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM