Redirect Rewrite for Joomla Root Domain Only? - apache

I recently migrated an existing site between two domain names. I created 301 rewrite rules for all existing pages to their new, corresponding links and that appears to be functioning correctly.
Since I individually mapped the link rewrites I didn't have the need to apply a broad redirect all visitors. The issue I am experiencing is that I have not been able to successfully 301 redirect the root (home/index) only. I have tried redirecting / as well as /index.php, but those rules appear to interfere with my other rewrite rules. I'm guessing this has something to do with Joomla's core SEF rewrite rules, but I'm not sure.
Example:
Let's assume this is one of my redirects:
Redirect 301 /oldlink http://www.example.net/newlink
But someone somehow visits /oldlink25 (which doesn't exist and never has). The current setup where I am redirecting /index.php, which is my attempt to redirect the root only, will still redirect this visitor to the new site root. I'd prefer to 404 that visitor, and the old link, at the old domain instead.
Long story short, unless someone visits a link that has an individually declared 301 in the htaccess, how can I redirect visitors that hit the root only and not every visitor that hits any random link without a corresponding rewrite rule?

Related

ERR_SSL_PROTOCOL_ERROR on a domain forwarding to another [duplicate]

I inherited a domain that previously had a 301 redirect from the root ("/") to "/index.shtml"
I've removed the redirect and a different site on the domain, but people who visited the site in the past will have the redirect behavior cached in their browsers... for a terribly long time, unless they manually clear their caches.
Anyone trying to go to example.com in these browsers will be sent to example.com/index.shtml before they even make any HTTP requests. Right now this is a huge problem because there is no index.shtml, but is there something I can do with headers to tell browsers to "forget about that redirect you just did!"?
The short answer: There is no way to tell the browsers of the users to "forget" the R 301 redirect. 301 means permanent, it can be only undone on action of the user or when the cache expires.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2
Similar Q and A on Stackoverflow:
Apache - how to disable browser caching while debugging htaccess,
Cannot remove 301 redirect
Try to avoid 301 redirects and use 302 (temporarily) instead. Here is an article how to set no cache for 301 redirects (didn't try it):
https://github.com/markkolich/blog/blob/master/content/entries/set-cache-control-and-expires-headers-on-a-redirect-with-mod-rewrite.md
What you could do in your scenario: You could add a header redirect to the file index.shtml, which sends the user to the original file, where he should usually go.
This can be done by a clear data-only cache.
It can remove all,.htaccess redirects changes from the browser.

guidelines for htaccess code to transition users to new website

Suppose I have an old website with 10 webpages, and I want to deprecate it and move visitors to a new website with 100 webpages.
Two of the webpages of the old website map directly to two corresponding webpages on the new website. All other pages on the old website should go to the new website's home page. How to set that up?
I know I can use .htaccess in the public_html folder of the old website to create some permanent redirect rules for individual pages. So for the two pages that need to map one-to-one, I can do:
Redirect 301 /oldfile1.htm http://www.example.net/newfile1.htm
Redirect 301 /def/oldfile2.htm http://www.example.net/123/456/newfile2.htm
But what about all the other webpages on the old website? This is where my knowledge of .htaccess lacks. Does the .htaccess stop executing when it reaches one of the redirects above? If so, then perhaps I simply place the following AFTER the above code to catch the remaining pages?
Redirect 301 / http://www.example.net/
Or, something else? Also, will the redirect directly above map all webpages it sees to the home page of the new website (I assume so), or a matching directory/webpage page on the new website? -- That is, I don't want the situation where http://www.olddomain.com/abc/Oldfile1234.html takes users to http://www.example.net/abc/Oldfile1234.html on the new website (rather, it should take users to http://www.example.net) since most webpages do not map one-to-one.
Lastly, in the .htaccess file on the old website public_html directory, how to account for users coming from https versus http, and www versus non-www URLs?
I'm hoping there's common strategy people use for this sort of thing, since it should be fairly common, so I don't have to re-invent one.
You should be using RedirectMatch for precise matching using regular expressions. You can place these rules in root .htaccess:
RedirectMatch 301 ^/oldfile1\.htm$ http://www.example.net/newfile1.htm
RedirectMatch 301 ^/def/oldfile2\.htm$ http://www.example.net/123/456/newfile2.htm
RedirectMatch 301 ^ http://www.example.net/

Preventing a double redirect with htaccess

I'm trying to create a redirect in-between page of sorts, because the URL that I'm redirecting TO includes more information than the URL I'm redirecting FROM. I'm using a short domain (hrci.me) with an htaccess file to redirect to the full domain (currently reachchallenges.infectionist.com). An example would be:
hrci.me/ch123
The path, ch123, includes the identifier that lets me know it's a challenge link (ch), and the 123 is the challenge ID. Each challenge has a title that I like to append to the end of the URL for SEO purposes. This example URL would redirect to:
reachchallenges.infectionist.com/challenge/123/Challenge+Title
The "Challenge+Title" part is stored in the database and needs to be retrieved by the challenge id, so I wrote a simple PHP script that does just that and then handles the redirect itself. My htaccess rule looks like this:
RewriteRule ^ch([0-9]{1,4})(/)?$ redirhandler.php?chid=$1 [L]
So the request to /ch123 should redirect to redirhandler.php?chid=123, which would get the title then redirect to the other domain at /challenge/123/Challenge+Title. The problem is, the short domain is set up to forward all incoming requests to the long domain, maintaining the original path (so hrci.me/something would redirect to reachchallenges.infectionist.com/something), and I'm finding that after the htaccess handles the rewrite to redirhandler.php, it then redirects that to reachchallenges.infectionist.com/redirhandler.php...
Basically, I need it to ignore any further redirects if the path is redirhandler.php, allowing the php script to handle the rest o the redirect. I'm thinking a RewriteCond is how I might do this, but I can't figure it out.
It sounds like your rule that forwards all incoming requests to the long domain is higher up in the .htaccess file than the more specific rule for /ch* requests. Try putting the more specific rule before the more general one.

.htaccess redirect when domain name is unknown

I have a site that I am not sure what the domain name will eventually be when it's live, but as I am working on it I access it through a local server. One of the directories on the site needs to be redirected. To save time when the site goes live (and also just to learn how) I am trying to write a .htaccess statement that will redirect the directory regardless of what the domain name is. Currently I access the site through:
http://phuk9220/
I want this directory:
/audio/help-and-faqs/
to redirect to:
/audio/help-and-faqs/welcome/
Now, I can easily do this with:
RedirectMatch 301 ^/audio/help-and-faqs/$ http://phuk9220/audio/help-and-faqs/welcome/
However, it means changing the http://phuk9220/ to whatever domain will it will eventually be on. Is there anyway of changing the domain dynamically depending on where it actually is ?
Thanks in advance and if you have any questions, please ask.
Alex
Simply omitting the domain name entirely should do the redirect on the same domain that was requested.
RedirectMatch 301 ^/audio/help-and-faqs/$ /audio/help-and-faqs/welcome/

Proper 301 redirect for sites

I have a bit of a complex question. I am moving sites from
http://www.hikingsanfrancisco.com
to
http://www.comehike.com
The directory structures will not be the same throughout both sites. What are some of the best practice things I can do in order to retain most of my existing SEO strength in both the general domain and individual pages for searches related to the other pages?
Thank you,
Alex
If most of the URLs are staying the same and just the domain is changing, you could create an .htaccess file in the root folder at the old site with the following:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.comehike.com/$1 [R=301,L]
This will make hikingsanfrancisco.com/some-page go to comehike.com/some-page.
Otherwise in that same htaccess file you could add a line for each redirect. So if hikingsanfrancisco.com/big-hikes is now going to comehike.com/even-bigger-hikes the redirect would look like:
Redirect 301 /big-hikes http://www.comehike.com/even-bigger-hikes
That 301 tells Google to now consider the new URL correct.
To redirect the whole site no matter what to the new URL you could use this:
Redirect 301 / http://www.comehike.com/
A 301 Redirect, page by page, is the best option (If you can use regular expressions is easier). Redirect the old page to a page in the new site with similar content.
Use the change of address tool in Google Webmasters tools.
Try to contact some of yours referrals to change the links that target your site.