If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

301 Redirect from main webpage to folder

Started by Optimitron, Oct 24, 2022, 10:25 AM

Previous topic - Next topic

OptimitronTopic starter

Hello! I require assistance with implementing a 301 redirect. Specifically, I need to redirect site.com to site.com/block.

I have attempted the following methods:

Redirect 301 / http://www.site.com/block # unsuccessful
RewriteRule ^/index.php /block/$1 [L,R=301] # unsuccessful

However, I am encountering an error message stating "Cyclic redirection on the page". Could you kindly provide me with some guidance on how to resolve this issue? Thank you in advance for your help.
  •  


Pournima

To implement the desired 301 redirect, you can try out the following script in your .htaccess file:

RewriteEngine On
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^site\.com$ [NC]
RewriteRule ^(.*)$ http://site.com/block/$1 [L,R=301]

Additionally, you may find this link on 301 redirects helpful:
https://linchpinseo.com/htaccess-rules/
  •  

marissadsilva

This error typically occurs when there is a loop in the redirect process, causing the browser to continuously attempt to redirect, resulting in an error message.

To address this issue, let me provide you with a step-by-step approach to fix the problem:

1. Check for Existing Redirects: First, make sure there are no existing redirects in the server configuration or .htaccess file that may be conflicting with the new redirect you are trying to implement. Remove any conflicting redirects before proceeding.

2. Use RedirectMatch: Instead of Redirect or RewriteRule, you can use RedirectMatch to specifically target the root URL and redirect it to the /block directory. Here's an example of how you can achieve this using RedirectMatch:

  ```
  RedirectMatch 301 ^/$ http://www.site.com/block
  ```

  This directive will redirect any request for the root URL to /block with a 301 status code.

3. Clear Browser Cache: After implementing the redirect, clear your browser cache and test the redirect again to ensure that any previous redirect loops are not being cached by your browser.

4. Check Server Configuration: If you're still encountering the cyclic redirection issue, check your server configuration (e.g., Apache, Nginx) to ensure there are no conflicting redirect rules at that level.

5. Test and Monitor: Once the redirect is in place, test it on different browsers and devices to ensure that it is working as expected. Monitor your site traffic and server logs to identify any potential issues related to the redirect.

By following these steps and using RedirectMatch to target the root URL specifically, you should be able to resolve the cyclic redirection issue and successfully implement the 301 redirect from site.com to site.com/block. If you continue to encounter problems, consider reaching out to your hosting provider or web server administrator for further assistance.
  •  

aHortTikle

Your current setup bombs due to the redirect catching all requests including /block. The fix is trivial - add a negation condition to exclude /block URLs from the redirect. For instance:

RewriteCond %{REQUEST_URI} !^/block
RewriteRule ^$ /block/ [R=301,L]

This breaks the infinite loop by telling Apache to redirect only root requests, not redirected targets.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...