HTACCESS Redirect Instructions
December 19, 2024 ยท AI Conversations
### Redirect Entire Domain to Another Site
If you want to redirect all traffic from your domain to another site:
RewriteEngine On
RewriteRule ^(.*)$ https://www.newsite.com/$1 [R=301,L]
### Redirect a Specific URL to Another Site
If you want to redirect a specific page or path:
RewriteEngine On
RewriteRule ^old-page/?$ https://www.newsite.com/new-page [R=301,L]
### Redirect Based on Conditions (e.g., Redirect Only Mobile Users)
You can also use conditions to redirect traffic based on specific criteria, such as user agents:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "Mobile|Android|iPhone" [NC]
RewriteRule ^(.*)$ https://m.newsite.com/$1 [R=301,L]
### Notes:
1. **Backup**: Always back up your `.htaccess` file before making changes.
2. **Cache**: Use `R=302` for temporary redirects while testing to avoid caching issues.
3. **Priority**: Place the redirect rules at the top of your `.htaccess` file to ensure they're applied first.
4. **SSL**: Ensure the target URL uses HTTPS if your site is SSL-enabled.
Let me know if you need help with a specific case!