Welcome to WebmasterWorld Guest from 54.227.83.19

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Loop trying to make Wordpress admin URL extensionless

     

gapao99

7:01 pm on Apr 17, 2011 (gmt 0)



Hi.

My problem looks simple: make my wordpress admin blog url go from > mysite/wp-admin to mysite/admin

I want to customize all my wordpress admin installation and transform urls like mysite/wp-admin/edit.php on something like mysite/admin/newpost

My problem is that i'm trapped on a loop.

here is .htacess

RewriteEngine On
RewriteBase /wordpress/

#Here we convert any URL with wp-admin on it to admin friendly url

#the line below DOESN'T resolve the loop problem!
#RewriteCond %{THE_REQUEST} ^GET\ (.*)\ HTTP
RewriteCond %{REQUEST_URI} wp-admin/(.*)$
RewriteRule wp-admin/(.*)$ admin/$1 [R=301]
RewriteRule ^/(.*)$ wp-admin/$1 [QSA,L]


#here we make the basic rewrite
RewriteRule ^admin/(.*)$ wp-admin/$1 [QSA,L]



So, how to avoid this loop?

thanks for any help.

my best

g1smd

7:30 pm on Apr 17, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Here's the problem. Mod_rewrite cannot change URLs. It merely acts on URL requests received by the server after a link is clicked.

In order to "change" your URLs you must change the links on your page so that they point to the URLs that you want your users to "see" and "use".

Mod_rewrite redirection is used merely to redirect requests for the "wrong" URL to the right URL. This action tells searchengines to update their indexes, and allows people following outdated links on other sites or in their browser bookmarks to reach the right URL.

gapao99

10:02 pm on Apr 17, 2011 (gmt 0)



Hi.

I know that modrewrite just rewrite and don't change the URL. I mean "change" when I wrote.

My problem is: I need to rewrite
mysite.com/admin -> mysite/wp-admin

AND i need rewrite too
mysite.com/wp-admin -> mysite.com/admin

My problem is how to avoid this loop? Is possible?

thanks
my best

g1smd

10:13 pm on Apr 17, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You cannot have two rewrites. Additionally, a rewrite is a URL to file translation. Your examples are both for URL to URL translations, more commonly known as a redirect. The terminology you use here is crucial in defining what you want to do.

Please clarify that you want a redirect and a rewrite.

If so, test THE_REQUEST with a preceding RewriteCond before the redirecting rule. This ensures only direct client requests are redirected. The pattern for this condition should match the literal "GET /requestedpath HTTP/1.1" request sent by the browser.

gapao99

10:44 pm on Apr 17, 2011 (gmt 0)



Hi. Thanks for you answers.

Sorry, i didn't clarify the problem. So let's do it.

When I enter the following URL, for example

mysite/admin

I want it to access mysite/wp-admin/index.php, what I already acomplished with the rewrite rule

RewriteRule ^admin/(.*)$ wp-admin/$1 [QSA,L]

That is already nice. I can change the wordpress menus via plugin and make them to point to friendly URLs, like mysite.com/admin/newpost (which appoint to mysite.com/wp-admin/edit.php).
That's working, perfectly.

BUT...

there's a lot of links inside wordpress, all of them with the href 'wp-admin/something.php', and would be insane change all these URLs, so i figured out to make the rewrite:
RewriteCond %{REQUEST_URI} wp-admin/(.*)$
RewriteRule wp-admin/(.*)$ admin/$1 [R=301]
RewriteRule ^/(.*)$ wp-admin/$1 [QSA,L]


that works ALMOST fine, except by the fact that this rules and the rule above together create a loop.

I think the problem can be solved via THE_REQUEST if I could detect if a request is a REDIRECT. So, i could do the following rewrite and avoid the loop:

RewriteCond %{THE_REQUEST} "IS NOT A REDIRECT"
RewriteRule ^admin/(.*)$ wp-admin/$1 [QSA,L]


where "IS NOT A REDIRECT" is something i didnt figured out yet :(

thanks for your time, and thanks if could give any clue about what to do here...

my best

g1smd

11:02 pm on Apr 17, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Yes, you need to use a RewriteCond before the redirect. It should test THE_REQUEST and the pattern should match the URL that was requested when the request has to be further redirected (that's redirected, not rewritten). The pattern will match the literal "GET /requestedpath HTTP/1.1" request. Do not test REQUEST_URI. This pointer is altered by internal rewrites. Instead, test THE_REQUEST. There are many examples of this code in previous threads in this forum, some only days ago.

It would not be "insane to change the links". It is REQUIRED that you change the links. URLs are defined in links and searchengines take a dim view of sites where clicking a link in the internal navigation leads to a redirect instead of content. These flip the "low technical quality" alert.

You also need the [L] flag on every rule.

g1smd

11:12 pm on Apr 17, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You'll need something like this:

# Redirect URL to URL
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-admin/[^\ ]*\ HTTP/
RewriteRule ^wp-admin/(.*)$ http://www.example.com/admin/$1 [R=301,L]
#
# Rewrite URL to internal file
RewriteRule ^admin/(.*)$ /wp-admin/$1 [QSA,L]


You MUST also change the links found on your pages.

gapao99

11:58 pm on Apr 17, 2011 (gmt 0)



Hi.

Nope. The loop doesn't occur anymore, but it's not rewriting urls like wp-admin/something to admin/something.
Your code should work fine, i don't get it why isn't working.

thanks

jdMorgan

8:12 pm on Apr 25, 2011 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Delete your browser cache and try again. Forcing a page reload is not enough... Delete the cache.

Although you may get this code to work, be aware that you are committing SEO suicide by using it. Re-read g1smd's comments above. You must modify the WP configuration or the script itself to produce the correct URLs. This is *required* if you want to avoid disastrous damage to the ranking of your site in search engines.

Given a choice, I would leave your wp-admin URLs alone and forget this whole project, rather than using the "bad solution" discussed in this thread. The redirect code may very well work, but it is not what you want to do if you care about your site's search ranking at all. Each of your pages must link to correct URLs, and there is no "redirect-based quick fix" for that.

Jim
 

Featured Threads

Hot Threads This Week

Hot Threads This Month