Redirects in .htaccess

PHOTO EMBED

Wed Jan 25 2023 12:23:27 GMT+0000 (Coordinated Universal Time)

Saved by @dphillips #server #apache

### Normal redirect from path to path ###

RewriteRule ^source/path$   /target/path [R=301,L]


### Redirect from query parameters ###

# For every path
RewriteCond %{QUERY_STRING} ^id=1&lang=de&newsid=30&subcat=8$
RewriteRule ^(.*)$   /target/path [R=301,L]

# Only for specific source path (here /index.php)
RewriteCond %{QUERY_STRING} ^lang=de&id=1$
RewriteRule ^index\.php$   /target/path [R=301,L]

# To purge the query parameters, add a ? at the end of the target path.
# The target path from the previous example would then be "/target/path?"
content_copyCOPY

https://simonecarletti.com/blog/2009/01/apache-rewriterule-and-query-string/