How can I redirect only my homepage to a different URL on a different server? - redirect

I am trying to redirect my company's home page (let's call it example.com) to a new webpage I built : example.net, without losing any archive and sub pages, i.e when a user navigates to example.com it will redirect to example.net, but when they click on "about us" I want it to go back to example.com/aboutus.
I can get it to redirect but every time a user clicks on a link (such as about us) the browser will try to load example.net/aboutus rather than example.com/aboutus, which does not exist.
I have tried many different redirect commands, 301 commands, .htaccess as well as adding redirects to the index page. Everytime I get the homepage to open to the new URL
I have attached my index page code.
<?php
/**
* Copyright 2013
* #author
*/
include_once($_SERVER["DOCUMENT_ROOT"]."/example.php");
//print_r($_SERVER);
$pageArr = explode("/", $_GET["q"]);
$_GET["q"] = $pageArr[0];
if($pageArr[1]){
$_GET["z"] = $pageArr[1];
}
if(!$_GET["q"]){
$_GET["q"] = "home";
}
$mDevice = null;
if($_GET["print"] == "true"){
$mDevice = "standard";
}
//Begin defining the main page
$WebPage = new xyWebpage($_GET["q"], $mDevice);
//$WebPage->setCharset("ISO-8859-1");
showPage();
function getPageName(){
return $_GET["q"];
}
?>

I'm not a PHP guy, but depending on your platform you can use either:
MOD_REWRITE Module for Apache or IIS re-write module.
Both of these support re-writing URL's which can match your use case.
I'm curious why you would just not replace your home page that you are redirected from on the same server(s), but in any case, since you already have the redirect working you only need it on the .net server. You will need two rules, one to stop processing if it's a root URL request, and then one for all other requests that will re-write the root back to your .com address. You need that first rule so you don't create a loop between your servers.

Related

Drupal 7 Webform redirect

We have a Drupal 7 webform that redirects to a url upon successful submission.
What we need to do is redirect the user if they land on the same webform again and have already submitted.
Do we need a module for this, or do it programmatically?
Thanks in advance.
I looked through the webform module and didn't find any setting that will redirect the user if the user has already submitted a form, so I think you need to do it programmatically.
Note: It might be possible without a custom module by using the rules module. I haven't tried this.
To do it programmatically you could do something like below. It implements the hook_node_view() and checks if the user has already submitted anything by using the webform api function webform_get_submission_count(). (edit: the custom module in this example is called example_webform)
<?php
/**
* Implements hook_node_view().
*/
function example_webform_node_view($node, $view_mode, $langcode) {
global $user;
module_load_include('inc', 'webform', 'includes/webform.submissions');
$submission_count = webform_get_submission_count($node->nid, $user->uid);
if (!empty($submission_count) && $submission_count > 0) {
$redirect = $node->webform['redirect_url'];
drupal_goto($redirect);
}
}
As it is now it will reuse the page that is used when the form is submitted, so if you choose to do this remember to make the success page reflect this. (E.g. it would be strange for the success page to say "your post has been saved" if the user lands on it for the second time.) Or you could replace the $redirect with another page than the one from the webform setting.
Also note that the webform will still add the message "You have already submitted this form. View your previous submissions." if this is enabled.
So here is the solution that we ended up going with.
I saved the webform and made it available as a block
I created a page to hold the webform
I configured the block to appear above the page content
In the page content I put in some javascript to detect if the form element was present - if not forward to the correct url
So the webform redirects correctly upon submission(set in the webform settings), and it then redirects if the user lands back on that page and has completed the webform.

Laravel Redirect to subdomain before loggin

I want to create script that's going to be using different sub-domains as user accounts.
The problem i have is, i would like to create script that's going to be redirecting user just before calling log-in attempt, so the session will be saved on sub-domain, not the main domain.
However, I do not want to share the sessions all around, i want to have it, so one user can be logged on his own sub-domain. So setting up
".example.com"
in config file is not way out for me.
EDIT:
Routes:
http://pastebin.com/kgaKJCWx
controller:
http://pastebin.com/73xsejG4
view:
http://pastebin.com/W8eWGrNA
The simplest solution I can think of would be to just use javascript to adjust the subdomain in the form action attribute. Something along the lines of this:
$('form').on('submit', function(){
var username = $(this).find('input[name=username]').val();
var subdomain = username.toLowerCase(); // you might want to do other things here as well
var newAction = $(this).prop('action').replace('yourdomain.com', subdomain + '.yourdomain.com');
$(this).prop('action', newAction);
});
So when the form is submitted, before it actually gets sent the action is updated with a subdomain. You could also use a placeholder in your original action and replace that with the actual subdomain.

PhalconPHP - redirection to home page always adds /index in the URI

I'm working on my first app in PhalconPHP so I'm deep in the documentation while working, but this doesn't seem to be covered.
Let's say that my app is running on www.myapp.tld. In some situations I need to redirect the user back to the home page and for that I'm using the following code:
if ($haveToRedirect) {
$this->response->redirect();
$this->view->disable();
return;
}
Instead if redirecting to www.myapp.tld, the user is redirected to www.myapp.tld/index. I've tried different redirect calls, but all give the same result:
$this->response->redirect('');
$this->response->redirect('/');
$this->response->redirect('/', TRUE);
In the app's bootstrap I've set the BaseUri to be '/':
$di->set('url', function() {
$url = new Phalcon\Mvc\Url();
$url->setBaseUri('/');
return $url;
});
Is there a way to avoid "index" being added and just have it redirect to "www.myapp.tld"?
If a file is not specified, you will be directed to the index page in that directory by default. You need to specify a file location. Also try URI, not URL
The cause of redirection to "/index" was actually in the Permission class I made several weeks ago. It had:
$this->response->redirect('index');
for every controller that guest could not access to. Since I added new controllers I was continuously redirected to index, and noticed that redirect comes from somewhere else when I removed the conditional redirects I've put in the controller.
Anyway, this is it. Lesson learned - next time grep for 'index' before asking for help. :)

TYPO3: 404 for restricted access page instead of login form

I have a link pointing to restricted page. When I access the link directly in logout status, its redirect to 404. Actually it should redirect to login form.
I tried:
config {
typolinkLinkAccessRestrictedPages=PAGE_ID
typolinkLinkAccessRestrictedPages_addParams = &return_url=###RETURN_URL###&pageId=###PAGE_ID###
}
Not working.
Also I tried the login status redirect plugin, no use.
Anyone know how to do this? I am using TYPO3 version 4.4.8.
As this is still unanswered, does this help?
Valid for TYPO3 < 8.x
# Check if user is logged in:
[usergroup = *]
# do something
[else]
page.config >
page.config.additionalHeaders = Location: http://www.yourdomain.org/login.html
[end]
I recently posted this to another questions and it crossed my mind that it might be a suitable workaround for your probem.
Found here
I'm not sure how to make redirection work correctly, but perhaps a bit of background will be helpful.
typolinkLinkAccessRestrictedPages only interacts with link generation. That way, anywhere you have a link to an access restricted page, you should get a link that points to the "PAGE Id" page. I suspect you are using your login pid in place of PAGE Id, which I guess should work, but I haven't used this particular feature. I have typolinkLinkAccessRestrictedPages = NONE which makes all links show up, linked to the correct url, but only users who are logged in will successfully load those pages.
If anyone, without being logged in, uses a bookmark to an access restricted page, or they click on one of these links, or directly type in the address, or whatever, they will run into TYPO3's 404 handling (with the error message: ID was not an accessible page). To change how TYPO3 handles these errors, you need to change what TYPO3 does via this setting in localconf.php:
$TYPO3_CONF_VARS["FE"]["pageNotFound_handling"]
I don't know if there's a clean way to just automatically redirect to the login page without hacking the pageNotFound_handling.
As far as the typoscript solution, that wouldn't work for my site, because the trigger isn't whether or not someone is logged in (often they will not be logged in)--the trigger for my site is trying to access a protected page when you are not logged in. I don't want it to redirect everyone who isn't logged in because a lot of pages don't require any login.
Fe_login cannot alone do this...
Follow these steps::
Install "pagenotfoundhandling" extention after felogin login
configuration.
Configure 403 page as login page in "pagenotfoundhandling" extention configuration.
Then, when you try to access "Access restricted page", "pagenotfoundhandling" will redirect to login page then pagenotfoundhandling handle redirect to again requested page. I have tested this on TYPO3 6.2.14
And I found an other workaround that looks like it should work fine.
# pages and subpages starting at 123 and 321 are restricted
[PIDinRootline = 123,321] && [loginUser = ]
page.headerData.666 = TEXT
page.headerData.666 {
data = getIndpEnv:TYPO3_REQUEST_URL
wrap = <meta http-equiv="refresh" content="0; URL=/passwort/?referer= | " />
}
[global]
Important notice: Do not restrict the complete page, only all contents of the page. Otherwise RealURL will trigger the 404 handler.
At the moment page.config.additionalHeaders (like used by #Mateng) does not support stdWrap, though you cannot add a referrer to redirect to the desired page after login (see TYPO3 Forge and vote for feature request).
Complete solution :
1. first in typo3conf/LocalConfiguration.php you have to add:
'FE' => [
'pageNotFound_handling' => 'REDIRECT:/login/',
"pageNotFound_handling_statheader" => 'HTTP/1.1 404 Not Found',
...
],
then add to typoscript :
'
config {
typolinkLinkAccessRestrictedPages = YOUR_LOGIN_PAGE_ID
typolinkLinkAccessRestrictedPages_addParams = &return_url=###RETURN_URL###
}
plugin.tx_felogin_pi1.redirectMode = referer
'
Because there seems no proper solution for this behaviour of TYPO3, I use the following workaround with RealURL.
Create a 404 page in TYPO3
set the Speaking URL path segment to "404-error" and check
Override the whole page path
Add a text that describes what is happening (i. e. "Page doesn't exist or is restricted, please login")
Add the felogin plugin to that page and hide it when users are logged in
Set [FE][pageNotFound_handling] = /404-error/ in the install tool
This 404-error page is shown every time a user requests a page that he is either not allowed to see or a page that does not exist. When the user uses the login form on the page, he will find the proper content immediately after login because the URI did not change at all (when there is no redirect configured for the fe_login plugin).

How To Redirect From a Control Using MVC2

I have been tasked with creating a user control to live in our master page that allows users to switch between accounts. This way, we can allow users to change their account without having to go back to the accounts page. This seemed like a legitimate and perfectly straightforward task.
I've built the control and added it to the master page using Html.RenderAction. The last step is for me to redirect the user to the home page for that account. In order to do this, I build a route to the home page and attempt return RedirectToRoute(route).
When I attempt this, I get this error:
Child actions are not allowed to perform redirect actions
Anyone have any ideas on how to resolve this or have I coded myself into a box
Thanks in advance
You can cheat with an ugly hack:
[ChildActionOnly]
public ActionResult SomeUserControlAction()
{
// ... some processing
var url = Url.RouteUrl("routeName", new
{
action = "foo",
controller = "bar"
});
Response.Redirect(url);
return null;
}
It's so ugly that I feel ashamed for even mentioning it, but it works.
Another possibility would be to pass the url as part of the view model to the view and perform the redirect in javascript by setting window.location.href to the new url.