简体   繁体   中英

.htaccess Redirect to a URL that uses a rewrite rule

I have Redirect like so:

Redirect 301 /url-1 /url-2

However, /url-2 matches a rewrite like such:

RewriteRule ^([^.]+)$ index.php?view=$1 [QSA,L]

This is redirecting /url-1 to:

/url-2?view=url-1

How can I get this to redirect and then rewrite correctly?

Few suggestions:

  1. Don't mix Redirect directive with mod_rewrite rules
  2. Keep redirect rules before rewrite rules.
  3. Skip files and directories from last rule

You can use these rules:

RewriteEngine On

RewriteRule ^url-1/? /url-2 [L,NC,R=301]

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+?)/?$ index.php?view=$1 [QSA,L]

Remember to clear your browser cache before testing this.

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