Home > Blockchain >  .htaccess redirect Home page " domain" to new path
.htaccess redirect Home page " domain" to new path

Time:02-12

I need to redirect domain.com to new path on same domain >> domain.com/?viewr=UNESCO/$1 when open domain.com how can do it by httaccess ?? Any help would be appreciated.

CodePudding user response:

To redirect example.com/ to example.com/?viewr=UNESCO/$1 then you would need to use mod_rewrite in order to check the query string. Try the following at the top of root .htaccess file:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^$ /?viewr=UNESCO/\$1 [R=302,L]

The literal $ in the substitution string (2nd argument to the RewriteRule directive) needs to be backslash-escaped to prevent $1 being interpreted as a backreference (which is empty).


UPDATE: If you are using this in a virtualhost context (ie. directly in the <VirtualHost> container, not inside a <Directory> container) then you will need to adjust the RewriteRule pattern from ^$ to ^/$. In other words:

:
RewriteRule ^/$ /?viewr=UNESCO/\$1 [R=302,L]

Reference:

  • Related