homepage Welcome to WebmasterWorld Guest from 107.20.25.215
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / WordPress
Forum Library, Charter, Moderators: lorax & rogerd

WordPress Forum

    
301 redirect for wp-admin
virtualreality




msg:4684407
 7:43 am on Jul 2, 2014 (gmt 0)

Hello, I noticed that my site's www.mysite/blog/wp-admin page creates 302 redirect. How can I make this 301? thanks.

 

phranque




msg:4684470
 12:08 pm on Jul 2, 2014 (gmt 0)

are you using apache's mod_rewrite or is some other method used to generate the redirect?

virtualreality




msg:4684571
 4:58 pm on Jul 2, 2014 (gmt 0)

Hello, I use this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

not2easy




msg:4684600
 6:23 pm on Jul 2, 2014 (gmt 0)

That is normal, the www.mysite/blog/wp-admin page is not supposed to be indexed, so it makes no difference. It really is a temporary redirect.

lucy24




msg:4684619
 7:34 pm on Jul 2, 2014 (gmt 0)

Now, wait. There's nothing in the quoted code-- WP/CMS boilerplate-- that says anything about a redirect at all. The 302 is coming from somewhere else.

Redirects default to 302 unless you explicitly say 301. (The only exception I know of is mod_dir's directory-slash redirect, which issues a 301-- but that doesn't apply to you.) But there are many sources for redirects. You need to find it.

not2easy




msg:4684642
 8:55 pm on Jul 2, 2014 (gmt 0)

The source is in the core code of WP. The blog claims to be in a subdirectory called /blog/. It may or may not be physically located there. The settings entered in the user interface within the wp-admin files determines the URLs of files in WP. Mess with those at your own risk. The file is not necessarily located where the URL would indicate, but is shown at that URL using a 302. This is normal. When Google says to use 301s, they aren't referring to internal CMS URLs. The question really isn't how to fix it, it is why would you want to change it?

lucy24




msg:4684651
 9:18 pm on Jul 2, 2014 (gmt 0)

The file is not necessarily located where the URL would indicate, but is shown at that URL using a 302.

But, but,
:: splutter ::
no it isn't. The file is shown at that URL using a rewrite. If there were a redirect involved, the file wouldn't be shown at the originally requested URL. That's the difference between a redirect and a rewrite. 302 and 301 are both redirects ([R] flag, or almost any rule in any mod that gives the full hostname in the target).

not2easy




msg:4684665
 10:36 pm on Jul 2, 2014 (gmt 0)

I go to login at a site I have set up like this, with WP installed in a subdirectory, but accessible at the root meaning that if I browse to http://www.example.com/ I will see the WP content.

If I go to http://www.example.com/wp-login.php it sends me to http://www.example.com/blog/wp-login.php. This is not a rewrite. It is a redirect and it is a 302 which causes no one any problems and it is controlled withing the internal settings configured within the user interface. Here's the header:
HTTP/1.1 302 Moved Temporarily

I don't normally have a 302, because I know where the blog is installed and I go there to login but I can cause a 302 by asking for the login file from the root directory. It is still normal and has no effect on anything, it is not a public page. IF the OP's situation is something different, then that is a different question.

lucy24




msg:4684685
 12:32 am on Jul 3, 2014 (gmt 0)

But then the 302 is originating with the WP software, not with mod_rewrite. So RewriteRules have no effect on what's happening.

not2easy




msg:4684703
 2:09 am on Jul 3, 2014 (gmt 0)

Yes, correct. The htaccess file shown is the default, boilerplate WP htaccess that gets automatically generated by WP on install. The lack of 301 comes from somewhere in the package itself, but I wouldn't bother trying to change it.

This is a little snippet from just one component that might help you see how WP does its own thing and messing with the WP generated htaccess can can have unintended consequences:
*/

/** Make sure that the WordPress bootstrap has run before continuing. */
require( dirname(__FILE__) . '/wp-load.php' );

// Redirect to https login if forced to use SSL
if ( force_ssl_admin() && ! is_ssl() ) {
if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
exit();
} else {
wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
exit();
}
}

/**
* Outputs the header for the login page.
*
* @uses do_action() Calls the 'login_head' for outputting HTML in the Log In
*header.
* @uses apply_filters() Calls 'login_headerurl' for the top login link.
* @uses apply_filters() Calls 'login_headertitle' for the top login title.
* @uses apply_filters() Calls 'login_message' on the message to display in the
*header.
* @uses $error The error global, which is checked for displaying errors.

phranque




msg:4684831
 1:38 pm on Jul 3, 2014 (gmt 0)

That is normal, the www.mysite/blog/wp-admin page is not supposed to be indexed, so it makes no difference. It really is a temporary redirect.


There's nothing in the quoted code-- WP/CMS boilerplate-- that says anything about a redirect at all. The 302 is coming from somewhere else.


you are both correct.
i hadn't paid much attention to the specific url in the OP, but it is normal behavior to respond to requests for privileged content or function with a 302 redirect to a login page.
this redirect would occur within WP code rather than in mod_rewrite.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / WordPress
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved