Why are is my homepage not redirecting? - .htaccess

Read a ton on creating the proper redirects, but still having an issue.
Moving a site from one domain unto another. The directory structure has changed as well. The subpages are working great, but the home page isn't. Here the code that I'm using:
RewriteEngine on
//301 Redirect Old File
RewriteRule oldsite.net newsite.com [R=301,L]
RewriteRule ^p_gallery.* http://www.newsite.com/gallery [R=301,L]
RewriteRule ^p_purchase.* http://www.shop.newsite.com [R=301,L]
Thanks!

Make sure you have enabled mod_rewrite.

Because your first rule is wrong:
RewriteRule oldsite.net newsite.com [R=301,L]
You can only match REQUEST_URI in the RewriteRule.
It should be like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.net$ [NC]
RewriteRule ^ http://newsite.com%{REQUEST_URI} [R=301,L]

Related

RewriteRule for hiding file extension and change file name

starting url - example.com/vid.php
wanted url - example.com/video
any help, pls, to write the RewriteRule
RewriteCond %{THE_REQUEST} /vid\.php\s [NC]
RewriteRule ???
With your shown samples, please try following htaccess rules file. Make sure to clear your browser cache before testing your URLs.
Also make sure that your vid.php file is present alongside with htaccess rules file.
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/vid\.php\s [NC]
RewriteRule ^ video? [R=301,L]
RewriteRule ^video/? vid.php [NC,L]
You don't even need a separate RequestCond here...
RewriteEngine on
RewriteRule ^/?vid\.php$ /video [QSA,R=301,L]
RewriteRule ^/?video/? /vid.php [QSA,END]
Test with a fresh anonymous browser window.
It is a good idea to start out with a R=302 temporary redirection and only change that to a R=301 permanent redirection once you are satisfied.

htaccess redirect subdomain to directory

I need help to write proper rewrite rules in my htaccess files.
I need to redirect something like fr.example.com to example.com/fr, because we recently changed the whole website and the multilingual system is managed differently. The structure and the pages too.
I managed to do that successfully with this piece of code:
RewriteCond %{HTTP_HOST} ^fr\.example\.com [NC]
RewriteRule (.*) http://example.com/fr/$1 [L,R=301]
My problem now is to write something more specific for pages, for example :
fr.example.com/discover/foo should go to example.com/fr/bar/foo (different path, nothing consistant)
BUT ! example.com/discover/foo should go to example.com/bar/foo (end of the url is the same in both english and french)
Right now, since I have some common 301 redirects, the french urls aren't redirect properly and lead to the english pages. For example that one :
Redirect 301 /discover/foo /bar/otherfoo
Successfully redirects example.com/discover/foo to example.com/bar/otherfoo but also redirects fr.example.com/discover/otherfoo
How can I write two different rules for english and french? I'll have to write a bunch of different rules since everything is very different from the old subdomain to the new directory, I don't mind.
Thanks !
EDIT
Please note that it's for a wordpress installation, and the htaccess starts with :
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
First the these rules:
RewriteCond %{HTTP_HOST} ^fr\.example\.com [NC]
RewriteRule (.*) http://example.com/fr/$1 [L,R=301]
should look like this :
RewriteCond %{HTTP_HOST} ^(www\.)?fr\.example\.com [NC]
RewriteRule (.*) http://example.com/fr/$1 [L,R=301]
In order to capture bot www & non-www requests for subdomain.
Also this rule :
Redirect 301 /discover/foo /bar/foo
Will capture both requests to domain and sub-domains and using mod_rewrite here is correct not mod_alias so , replace this line with :
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule ^discover/foo http://example.com/bar/foo [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?(fr)\.example\.com [NC]
RewriteRule ^discover/foo http://example.com/%2/bar/foo [L,R=301]
Note: clear browser cache then test.

.htaccess Redirect all pages to one page

htaccess snippets to redirect all pages to one page but none of them are working for me.
I need olddomain.com , olddomain.com/pricing , olddomain.com/about , etc all to point to newdomain.com.
So olddomain.com/pricing shout not go to new domain.com/pricing.
It should just go to newdomain.com.
How can I do this?
Nothing simpler then that.
If it are different webservers, you can write this on the old ones:
RewriteEngine On
RewriteRule ^(.*)$ http://www.newdomain.com [R=301,L]
^(.*)$ means everything
http://www.newdomain.com is the target
If it is still the same webserver
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(.*)newdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com [L,R=301]
It is pretty the same, but you have the condition, that the host is not newdomain.com.
RedirectMatch 301 (?i)/* http://www.yourdomain.com/WHATEVER
or
RedirectMatch 301 (?i)/OLD/* http://www.yourdomain.com/WHATEVER
This will go in the htaccess in your old domain root. If they are not on the same server you don't need the RewriteCond line.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain.com$ [NC]
RewriteRule ^(.*) http://newdomain.com/ [R=301,L]
Try this and let me know how it works for you.

Moving Website to new domain and site structure - redirects are only working for subpages not main site

I've read a ton on creating the proper redirects for my project. I found some helpful information, but still having an issue.
Ok, I moving a site from one domain unto another. The directory structure has changed as well.
I want the domain to redirect from a .net domain to a .com domain. Then redirect all of the website sub pages into the correct structure on the new domain. The subpages are working great, but the home page isn't. Here the code that I'm using:
RewriteEngine on
//301 Redirect Old File
RewriteRule oldsite.net newsite.com [R=301,L]
RewriteRule ^p_about.* http://www.newsite.com/about [R=301,L]
RewriteRule ^p_linkresources.* http://www.newsite.com/resources [R=301,L]
RewriteRule ^p_services.* http://www.newsite.com/services [R=301,L]
RewriteRule ^p_events.* http://www.newsite.com/events [R=301,L]
RewriteRule ^p_contact.* http://www.newsite.com/contact [R=301,L]
RewriteRule ^p_testimonials.* http://www.newsite.com/testimonials [R=301,L]
RewriteRule ^p_site_credits.* http://www.newsite.com/resources [R=301,L]
RewriteRule ^p_gallery.* http://www.newsite.com/gallery [R=301,L]
RewriteRule ^p_gallery.* http://www.newsite.com/gallery [R=301,L]
RewriteRule ^p_purchase.* http://www.shop.newsite.com [R=301,L]
I greatly appreciate any help!
This rule:
RewriteRule oldsite.net newsite.com [R=301,L]
Needs to be:
RewriteRule ^$ http://www.newsite.com/ [R=301,L]

Htaccess redirect for hundreds URL

I have old site with hundreds URL that look like that:
http:www.domain.com/Contact.asp?Pid=344
http:www.domain.com/Contact.asp?Pid=345
http:www.domain.com/Contact.asp?Pid=346
and so on ...
I need to move all of them permanent to 1 single URL :
http:www.domain.com/contact
I tried this:
RewriteCond %{QUERY_STRING} Contact.asp?Pid=([0-999]+)
RewriteRule ^http://www.domain.com/contact? [L,R=301]
But it doesn't work well.
The old site use ASP. The new site build on Joomla. The domain will be the domain from old site
You're close. You need to use the %{QUERY_STRING} variable like you did, but the var doesn't include the URI-path (the Contact.asp?) part. Also, your RewriteRule is missing a regex pattern. Try:
RewriteCond %{QUERY_STRING} Pid=([0-999]+)
RewriteRule ^/?Contact\.asp$ http://www.domain.com/contact? [L,R=301]
RewriteRule ^Contact.asp?Pid=(\d) /contact? [L]
Are the only pages you have on there the contact pages? You could just 301 the entire directory since they are all moving to one URL.
RewriteEngine on
RewriteBase /
RewriteRule ^/(.*)$ http://www.domain.com/$1 [R=301,L]

Resources