HTACCESS url in page REDIRECT - .htaccess

I have a url condo-search.co and it loads a blank page, I want to direct it to condo-search/en/index.php how do i do that using htaccess?

You can add this:
RedirectMatch 301 ^/$ /en/index.php
in your document root's htaccess file. Or if you want it to not externally redirect:
RewriteEngine On
RewriteRule ^$ /en/index.php [L]

Related

.htaccess redirect only root of a subfolder to another subfolder?

I have a site in "example.com/a" and would like to redirect 301 just url "example.com/a" to "example.com/b" and other data in "example.com/a" dont change address.
create .htaccess in "example.com/a" and try using several code like:
RewriteEngine on
RewriteRule ^$ http://www.example.com/b [R=301,L]
and
RedirectMatch 301 ^/$ https://example.com/b
and its redirect root but all other data in "example.com/a" show 404 error.
I have a lot of photos in "root/a" , just want to redirect the "root/a" address to "root/b" and the address of the photos remains the same.
For example, the "root/ a/pic.jpg" address will remain unchanged before and after the redirect,
How can i just redirect the "example.com/a" and other old address not change?
If I understood you well you need to redirect root/a to root/b while maintaining location of the rest of the pages, files?
This will do:
# Redirect Root Only
<IfModule mod_rewrite.c>
RewriteEngine On
#Uncheck line below to redirect 'index.php' as well
#Redirect 301 /a/index.php http://example.com/b/
#Redirect root only
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/a/$
Rewriterule ^(.*)$ http://example.com/b/ [L,R=301]
</IfModule>
# END Redirect Root Only
Need to redirect index.php, index.html, or other index pages too? Uncheck the line in code above. Because %{REQUEST_URI} ^/a/$ excludes all direct file paths including /a/index.html,index.php,index.py,etc.

301 /product?title=jar&id=190 to homepage

i'm trying to redirect a page to homepage and cant seem to make it work with .htaccess for some reason
/product?title=jar&id=190 to homepage
i've already tried
Redirect 301 ^/product?title=jar&id=190 /
and
Redirect 301 ^/product?title=jar&id=190 /index
and a couple other redirects but for some reason they are not working
Redirect directive works on URL path only. Since your URL contains a query String title=jar&id=190 you will need to use RewriteRule for this .
RewriteEngine on
RewriteCond %{QUERY_STRING} ^title=jar&id=190$ [NC]
RewriteRule ^product/?$ /? [L,R=301]

Redirect 301 specific pages and the rest to just one page

First I need to redirect these pages to another page in a different domain
Redirect 301 /example1 http://newdomain.com/test1
Redirect 301 /example2 http://newdomain.com/random1
Note the pages are not the same in the new domain (e.g., /example1 to /test1)
After that, I need redirect the rest of the pages to newdomain.com
E.g., Redirect 301 (everything else) to http://newdomain.com
Try below rule, using mod rewrite I am assuming you have mod rewrite enabled.
RewriteEngine On
RewriteRule ^example1$ http://newdomain.com/test1 [R=301,L]
RewriteRule ^example2$ http://newdomain.com/random1 [R=301,L]
RewriteCond %{REQUEST_URI} !^(example1|example2)
RewriteRule ^ http://newdomain.com [R=301,L]
If you want to use mod-alias , you can use these redirects :
RedirectMatch 301 ^/example1/?$ http://example.com/test1
RedirectMatch 301 ^/example2/?$ http://example.com/random1
#redirect everything else to the homepage of example.com
RedirectMatch ^.+$ http://example.com/
Clear your browser cache before testing these redirects.
Try this in your .htaccess
RewriteEngine On
RewriteRule ^(.*)$ http://newdomain.com/ [R=301]

.htaccess 301 Redirect: www2 to www

I want to redirect just one URL:
www2.mydomain.com to www.mydomain.com
I don't want to redirect sub directories, just that top url, if I find another one then I could write another redirect, but I can't seem to get this working?
Try adding this in the htaccess file in your www2 document root:
RedirectMatch 301 ^/$ http://www.example.com/
If the document root is the same for both www and www2 then you need to check the HOST header and use mod_rewrite to do that:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www2\.example\.com$ [NC]
RewriteRule ^$ http://www.example.com/ [L,R=301]

URL-based redirect with Htaccess

I have several domain aliases pointing to the same website like:
domain1.de/en/
domain1.de/de/
domain2.ch/de/
domain2.ch/en/
When someone opens a specific language-based sub-directory on a URL, I would like to redirect them to the start page, e.g. for domain1.de users shouldn't be able to access the sub-directory /en/ but be redirected to the start page. For the domain2.ch users should only have access to the directory /en/ and not /de/. How can I set this up with Htaccess?
This might be a helpful link to you;
htaccess redirect
for a 301 redirect entire directory it generated the following code:
//301 Redirect Entire Directory
RedirectMatch 301 domain2.ch/de/(.*) domain2.ch/en//$1
RedirectMatch 301 domain1.de/de/(.*) domain1.de/en//$1
Give this a try:
RewriteCond %{HTTP_HOST} ^de\.domain\.de$ [NC]
RewriteCond %{REQUEST_URI} ^(.*)/en/(.*)$ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/targetpage.php [R=301,L]

Resources