Forum Moderators: phranque

Message Too Old, No Replies

Help with mod rewrite regular expression

         

weilunt0219

4:54 am on Jul 25, 2012 (gmt 0)

10+ Year Member



I have the following rewrite rules setup in my site to mask the fact that I use wordpress.
RewriteRule ^wordpress/wp-login(.*)$ wordpress/login [R]
RewriteRule ^wordpress/login$ wordpress/wp-login.php [NC,L]



Wordpress logins usually generate large strings for URLs, for example, mine will generate:
http://localhost/wordpress/wp-login.php?redirect_to=http%3A%2F%2Flocalhost%2Fwordpress%2Fwp-admin%2F&reauth=1%3E


I want to take that entire thing and change it to:
http://localhost/wordpress/login


But the above rewrites only serve to break the poor thing. How do I get it to change the large URL to the simple one?

Thanks
Weilun

wilderness

3:49 pm on Jul 25, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I want to take that entire thing and change it to:
http: //example/wordpress/login


You need to make those corrections when the URL are created and within Wordpress, else you'll just be contumaciously chasing your tail as new URL's continue appear.

There are multiple Wordpress examples in the forum Library which you should find beneficial.

g1smd

4:16 pm on Jul 25, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Mod_Rewrite cannot and does not "change" URLs.

To change a URL, you need to alter the href part of the link that the user will click on. URLs are defined in links.

Mod_Rewrite does its thing after the link is clicked. It can redirect the user to a different URL or it can perform an internal rewrite to fetch content from a different location inside the server compared to that suggested by the path part of the requested URL.

Your above code contains a 302 redirect and an internal rewrite. They are coded such that you will get an infinite loop of requests.

lucy24

7:59 pm on Jul 25, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I got only this far:
I have the following rewrite rules setup in my site to mask the fact that I use wordpress


Like those TV cartoon burglars who wear burglar masks so everyone can see right away that they're burglars? :) You're not exactly "masking" if the old URL and new URL both say "wordpress" as large as life.

Wordpress logins usually generate large strings for URLs, for example, mine will generate:
http://localhost/wordpress/wp-login.php?redirect_to=http%3A%2F%2Flocalhost%2Fwordpress%2Fwp-admin%2F&reauth=1%3E

I think you're getting an additional problem by testing out the code in an environment that isn't set up for testing. Disencoded, the quoted line says

http://localhost/wordpress/wp-login.php?redirect_to=http://localhost/wordpress/wp-admin/&reauth=1>

Oops! Did that closing bracket sneak in from an encoded <a href .. blahblah> or similar element? It definitely doesn't belong in the query string-- at least not unless there's a matching < open bracket earlier.


Sorry, mods, but example.com obviously won't cut it here!

weilunt0219

8:45 pm on Jul 26, 2012 (gmt 0)

10+ Year Member



Oh, sorry about that. forgot to the ending bracket out when I was copying and pasting the URL. I had that ending bracket initially because I was trying to use the regex [^>]> before I swapped to [.*] The problem is still the same though, the rule will not redirect that large URL to a simple
http://localhost/wordpress/login

g1smd

8:58 pm on Jul 26, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Like I said, you have a badly coded infinite loop.

weilunt0219

11:36 pm on Jul 26, 2012 (gmt 0)

10+ Year Member



Ugh... I knew that g1smd... I was hoping you could fix it. Because the function I used in older Wordpress versions no longer changes all "href parts" on the site no longer works.

wilderness

12:00 am on Jul 27, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I was hoping you could fix it.


FWIW:
1) If he fixes it for you than outside of your present needs the process of learning is not beneficial to you. You'll just be back tomorrow or the next day asking for g1smd or another to fix something else for you.
2) Please read the forum charter. The primary reason this forum was created in 2003 or 2004 was so that webmasters could learn and comprehend how to navigate (whether reading or creating) their own syntax and solutions.

Please write my code has never been an option, per the forum charter.