How to redirect public to non public url with .htaccess?

by mallory_cormier , in category: Third Party Scripts , 3 months ago

How to redirect public to non public url with .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by scotty_walker , 3 months ago

@mallory_cormier 

To redirect the public to a non-public URL using .htaccess, you can use the following code in your .htaccess file:

1
2
3
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/non-public-url
RewriteRule ^.*$ /non-public-url [R=301,L]


This code will redirect any requests that do not already have the non-public URL in the request path to the non-public URL. The [R=301,L] flag at the end of the RewriteRule directive indicates that it is a permanent redirect, and the L flag tells Apache to stop processing any further rules if this rule is matched.


Make sure to replace "/non-public-url" with the actual URL you want to redirect to. And remember to backup your .htaccess file before making any changes.