We have a wordpress site http://10.10.10.10/sitename/.
When the user enters a "string" in the search bar and hits enter, the request is sent to http://10.10.10.10/?s= and is thrown the default Apache index.html.
Expected behavior: The user should be sent to http://10.10.10.10/sitename/?s= instead of http://10.10.10.10/?s=
What are the possible ways to implement a redirect from /?s= to /sitename/?s=
Thank you,
You have to use the wp_redirect() function of the wordpress
$url ="http://10.10.10.10/sitename/?s=";
wp_redirect($url);
here is the wordpress documentation page of this function
Related
I am making an intranet site in Wordpress that can be viewed from a specific IP or it redirects to the login page if it is accessed from another IP. I tried to redirect from .htaccess and from functions.php but with no success.
In functionts.php I put this code found in another post:
function ip_based_login() {
$visitor = $_SERVER['REMOTE_ADDR'];
$redirectTo = site_url('wp-admin');
if (!preg_match("/95.81.51.134/",$visitor)) {
wp_redirect($redirectTo);
}
exit;
}
add_action('init', 'ip_based_login');
This code gives me the error: The page isn’t redirecting properly in Firefox.
I deleted the code form .htaccess before I thought of posting.
How can I do this?
Try via plugin
Restricted Site Access
It has what you are looking for.
In wordpress, when you hit url like the following:
http://www.example.com/?author=1
If the author ID is valid then they will be redirected to the author URL, for example:
http://www.example.com/author/username
Then the hacker start attacking the username. How could I disable (?auther=xx) query in url?
for example redirect the request to another page like 404 (not found) page
I believe that dingo-d has it right, above, referring to the 301 redirect. I have installed 301 redirects on several Wordpress sites to accomplish this. I redirect [domain]/?author=* with a wildcard to my 404 page. I have watched my activity logs before and after implementing this. The malicious login attempts immediately switch from valid user names to the generic "admin."
Add the following filter to your functions.php file;
add_action('template_redirect', 'disableAuthorUrl');
function disableAuthorUrl(){
if (is_author())) {
wp_redirect(home_url());
exit();
}
}
This will check all incoming requests to see if the page requested is an author page, and if so, redirect to the homepage, or wherever else you choose.
I'm trying to use php redirects rather than using javascript to speed up my app. I've tried adding the header redirect calls within an action under the init hook since it runs after WordPress has finished loading but before any headers are sent. nothing happens. below is an example:
function redirect()
{
header("Location:http://www.website.com/");
die('should have redirected by now!');
}
add_action('init', 'redirect');
Any thoughts on how I can do php redirects?
thanks
Many times you can do this by signing into your hosted account and just managing DNS from your control panel.
Other wise add this to your index.php file
header("Location: http://www.example.com"); just above the line that starts with define.
UPDATED:
Review -
https://codex.wordpress.org/Function_Reference/wp_redirect
Thanks !!
When I try to redirect page using the header('Location: ...') function it is appending the redirect URL to current pages URL instead.
For Example, my current page is http://www.example1.com.
I have created a simple file called test.php with the code below in it:
header('Location: http://www.example2.com');
However it is currently redirecting the page to http://www.example1.com/http://www.example2.com instead of http://www.example2.com.
Any suggestion what should be the issue?
This issue has arisen after moving the site to a new server. I am running the site by doing host entry.
I have my wordpress blog at www.mysite.com , also I have my own php application at a subdomain l.mysite.com
I want the login credentials of WordPress in my PHP application. I figured out that by including the wp-blog-header.php from the root to my app.
I can use the user info OK.
I wanted to redirect users to www.mysite.com/wp-login.php?redirect_to=l.mysite.com . You can see here that I am specifying the redirect_to parameter. Wordpress ignores this and redirects to admin panel.
I think that worpdress doesn't allow redirect to an "external domain" , which I think is specified in wp_safe_redirect() function in wordpress. Is there any plugin which could ignore some domain to which redirect can happen?
I see that there are many login specific redirect plugins but none which could do to a new doamin.
Check this Plugin: http://www.theblog.ca/wplogin-redirect
Looks like it does what you want. Probably it's outdated, however, it should be trivial to create a plugin that fits your need.
A filter to start with is login_redirect, there is another filter in wp_safe_redirect() so you can prevent the domain you want to use being blocked.
To monitor redirects, checkout my Better HTTP Redirects Plugin.
+1 to #hakre . I don't have 15 rep so I can't upvote. Repost incase his
function cleanup_allowed_redirect_hosts( $hosts )
{
$allowed_hosts = array('first.domain.com', 'second.domain.com', 'etc.domain.com');
return array_merge( $hosts, $allowed_hosts );
}
add_filter( 'allowed_redirect_hosts', 'cleanup_allowed_redirect_hosts', 10, 1 );