htaccess to redirect submain with sub-pages on another server - .htaccess

I need to redirect my sub-domain http://listings.mywebsite.com/i/ to "mywebsite.com" but the trouble is, this "/i/" and all of the pages following this "/i" are hosted on another server. I created a redirect to direct "listings.mywebsite.com/" to my home page, so no problem there... But this "/i/" at the end is giving my trouble.
I tried several htaccess redirect scripts found within this site but none of them worked, likely because this /i/ are not on my server.
That is, if I go to "listings.mywebsite.com/i/" , I see a "document unreachable" error page because this "/i" somehow is connected to this company's server. However, if I go to http://listings.mywebsite.com , I'm redirected to my homepage.
I asked the company to remove me from their servers, but they are not doing it yet and are being slow if no response at all (something about keeping me active in their servers in case I decide to come back to them but I'm not.
Thanks much for any help!
Frank

Put this code in your DOCUMENT_ROOT/.htaccess file on listings.mywebsite.com host:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^listings\.mywebsite\.com$ [NC]
RewriteRule ^i/(.+)$ http://mywebsite.com/$1 [L,NC,R=301]

Related

Redirect An Unknown Source Domain To Subfolder Using .htaccess

I am interested in offering my users a "white label" service, wherein they will set up a CNAME record that points to my server.
For example, I would like client.theirdomain.com to actually redirect to https://example.com/client/, but keep the URL still as client.theirdomain.com (and, further, if they click a link that is actually https://example.com/client/something.html, it would appear to the user as client.theirdomain.com/something.html.
I attempted to do this in my .htaccess with the following;
RewriteCond %{HTTP_HOST} ^client\.(.*)\.(.*)$ [NC]
RewriteRule ^$ /client [NC,L]
For posterity, I also have a valid subdomain created (client.example.com) that directs to the root of my website, as well as a CNAME record created on a client's server (which points client.theirdomain.com to client.example.com).
When I attempt to use the above settings, however, I receive an error that there were too many redirects.
Thanks!

htaccess works with www.example.com but not example.com

I have installed Ghost, which needs nodejs to run. I'm doing this on an Apache Linux server via managed hosting. They kindly let me login with SSH access so I've been able to setup nodejs and Ghost using the standard installation instructions. I installed ghost to the root of my domain so in normal operation someone would go to example.com and it'll show them my blog. Well that's what I'd hoped.
However now when I've come to load Ghost in my browser I discover because I'm accessing it the way I am, and that Ghost doesn't do server configuration, I seem to need an htaccess file to be able to make the site reachable.
So, I have created this htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ http://127.0.0.1:65515/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:65515/$1 [P,L]
</IfModule>
With that saved to the root, if I go to example.com/ghost (the admin panel for Ghost) it works. Nothing wrong there, looks great. If however I try and visit the root, ie goto example.com, instead of showing me the index, it shows me index.js - that is, it literally loads the contents of Ghost's index.js file and displays it instead of parsing it and displaying the main index of the website.
IF however I go to www.example.com then it all works. So whatever the problem is it's because I'm not using www. in the domain.
I would prefer it to work both with or without the www in the URL though. I did try adding some solutions to redirect non-www requests to www.example.com to th ehtaccess but for some reason it still doesn't work (as in if I type example.com it doesn't redirect me to www.example.com).
I think maybe you should be using mod_proxy rather than mod_rewrite. At least, that's what I've used in the past. Apache will catch requests coming in on port 80 and then redirect them to port 65515 where your node server is listening.
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass
Like this:
ProxyPass / http://localhost:65515/
I figured it out. Wasn't anything to do with htaccess, or Ghost or nodejs or anything like it. No, instead the problem was the sodding server was caching the website. I discovered the setting to delete the cache and it all started working fine, so, this is now solved.

Redirecting parts of a web page in IIS

I have a "dummy" web site in IIS on a 2008 server that redirects users to the correct web site.
For historical reasons this box, and what everyone knows, is "mail.abc.com".
"mail" has now come to mean several other things, but people just type that name or have it bookmarked and expect to get directed to the "type of service" they are looking for.
mail.abc.com (ports 80 or 443) actually redirects to -> webmail.abc.com (port 443)
webmail contains a webportal for the users to sign into their email, but it also holds their personal web pages. These are accessed by going to ->mail.abc.com/~their_name
I want to create some type of rule that splits this into two pieces (we are splitting these two services onto 2 servers - one for the email part and one for their personal web pages)
so if you go to the generic page the redirect should goto webmail.abc.com
but if there is a "~", I want to redirect to a different location => webpages.abc.com/~their_name
I was looking at HTML redirects to do this, but I'm not sure how to split the typed-in URL, the "root" URL could be easily redirected, but how would I build something for any URL that had the tilde in it?
If you are able to use .htaccess, put a file .htaccess with the following configuration in the root folder of the mail.abc.com host:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/~(.*)
RewriteRule ^(.*)$ http://webpages.abc.com/~%1 [R=302,L]
RewriteCond %{REQUEST_URI} ^(.*)
RewriteRule ^(.*)$ http://webmail.abc.com%1 [R=302,L]
What happens:
Line 2 and 3 is the first set of RewriteCond and RewriteRule. The RewriteRule in the third line will redirect to http://webpages.abc.com/ only, if mail.abc.com was called with ~ in the URL segment. So if I try to open for example http://mail.abc.com/~m_eberhard I will be redirected to http://webpages.abc.com/~m_eberhard.
The next set in line 4 and 5 will redirect everything else to webmail.abc.com. If I try to open mail.abc.com/asdasdasd I will be redirect to webmail.abc.com/asdasdasd

ideas for a 301 redirect wildcards?

I'm having some trouble in finding an answer for a 301 redirect problem. The story goes like this:
I used to have a German language news site at www.punkto.ro. Every new article created with the site's CMS had the form: punkto.ro/articles/title-1234.html, where the 1234 is replaced by the article's number in the database.
For several reasons I had to redesign and opted for wordpress, which I placed in the root. I created a subdomain archive.punkto.ro and replaced the url variable "punkto.ro" in a config.php file with "archive.punkto.ro". Then I moved the site files to the subdirectory "archive". It works fine.
Of course, old article links in google now lead to a 404 response. To be sure, I also indicated the location of the archives on the 404, so people can go look there.
Now to the redirect: what I want to achieve is that when a user clicks a link in google punkto.ro/articles/title-1234.html, he/she should be redirected to archive.punkto.ro/articles/title-1234.html.
The strange stuff is that I can't find the folder "articles" in my file manager (cpanel OR ftp)... Does anybbody have any idea as to how the .htacces should look like?
Examples:
Old link: http://www.punkto.ro/articles/Staatschef_Basescu:_Rumaenien_einschliesslich_gesetzmaessig_fuer_Grexit_gewappnet-4169.html
New link: http://www.archive.punkto.ro/articles/Staatschef_Basescu:_Rumaenien_einschliesslich_gesetzmaessig_fuer_Grexit_gewappnet-4169.html
I don't think you have to create the .htacccess-file in the "articles"-folder. Just create it in the main folder.
I hope this will work for you:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?punkto.ro$
RewriteRule ^articles/(.*)$ http://www.archive.punkto.ro/articles/$1 [L,NC,R=301]
The RewriteCond makes sure that www.archive.punkto.ro will not be redirected again, the RewriteCond redirects every URL containing "articles/" to the archiv.

htaccess selective redirect

I am trying to redirect all sub-directory pages to main directory, except of a few pages (e.g. (somepage1.html).
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(de|ru)/somepage1.html
RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/(.*)$ /$2 [R=301,L]
Everything working except de/somepage1.html is redirected to home page (/), which is not acceptable. I wont it not redirected at all.
How can I achieve it
Thanks1
Well above rules are clearly excluding de/somepage1.html URL so it is most likely some other rule that is redirecting de/somepage1.html to /. Are you using wordpress or some other CMS tool by any chance? That might have its own rules in .htaccess file, check that please.
Also it would help to check web server's access log when this redirection happens.
the code I provided is working perfectly, so if somebody looking for this kind of a solution can use it without a fought.
The reason for not working is that my website were keeping cash and therefore was not renew frequently.

Resources