Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google      Sign In   
  • Create Account

Subscribe to HRA Now!

 



Are you a Google Analytics enthusiast?

Share and download Custom Google Analytics Reports, dashboards and advanced segments--for FREE! 

 



 

 www.CustomReportSharing.com 

From the folks who brought you High Rankings!



Photo
- - - - -

Transparent Redirect


  • Please log in to reply
7 replies to this topic

#1 skeddles

skeddles

    HR 1

  • Members
  • Pip
  • 7 posts

Posted 27 March 2009 - 10:59 PM

I want a transparent redirect, here my current code:

CODE
RewriteRule ^user/(.*) http://mydomain.com/homepage.php?u=$1 [NC]


which redirects from
mydomain.com/user/username

mydomain.com/homepage.php?u=username


But it changes the url in the address bar, which I don't want.

I've looked everywhere, but can't figure it out.



Also, for some reason it doesn't work if I take out 'user' (I just want mydomain.com/username )

EDIT: I figured out the first part, just took out the protocol/domain
that's only for the id, but there's also the optional '&m=edit' string at the end, which doesnt work now, us there a way too make it so it can just be domain.com/user/username/edit ?

If you can help, then thanks.

Edited by skeddles, 27 March 2009 - 11:32 PM.


#2 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 28 March 2009 - 08:57 AM

There are several things in your post that don't make sense, so I have more questions than answers.

First off, it's not a Redirect. What you're doing is a url Rewrite. There is no redirect at all in your single line .htaccess instruction, so if the URL is actually changing you need to figure out what's causing that. It's not your single line of .htaccess. So there's either more in that .htaccess file, another .htaccess somewhere in the path, or something in the php file that's firing a redirect.

This sort of thing is where a tool like WebBug can come in really handy because it doesn't actually follow the redirect. It finds one and reports it, just like the spiders do. So allows you to step though a series of redirects when you run into more than one redirect. I would encourage you to download and use WebBug, making sure to set it to HTTP Ver 1.1. It'll let you see more.

QUOTE
Also, for some reason it doesn't work if I take out 'user' (I just want mydomain.com/username )


You can't. Not unless every single page of your site requires a user to be logged in. Meaning there are no public pages at all. The reason being that RewriteRule ^(.*) will match anything and everything after the domain name itself. So will match every page. You need something to use a trigger. In this case it's the /user/ subdirectory. So unless every single username has to start with a certain character or string of characters --one that is not being used by anything else-- you can't.

QUOTE
EDIT: I figured out the first part, just took out the protocol/domain
that's only for the id, but there's also the optional '&m=edit' string at the end, which doesnt work now, us there a way too make it so it can just be domain.com/user/username/edit ?


Do you mean you did something at the file level? Because none of that stuff is mentioned at all in your current .htaccess rewrite.

Like I said, more questions than answers.

#3 skeddles

skeddles

    HR 1

  • Members
  • Pip
  • 7 posts

Posted 28 March 2009 - 10:58 AM

Thanks for replying.


I actually got nearly almost all of it working.

you can go to user/username, and it'll direct you to homepage.php?u=username, and if you put /edit at the end, then you can go into edit more, which I wanted,

the only problem now is that it doesn't work if you dont put domain.com/user/username/ (with a slash at the end)


Here's my code

CODE
RewriteRule ^user/(.*)/(.*) /homepage.php?u=$1&m=$2 [NC]


I want it to work whether or not there's a slash after the username.
Any ideas?



Also, I have a couple static redirects:
CODE
Redirect /register http://domain.com/register.php

but they aren't transparent the the one I have now, and if I do
CODE
Redirect /register /register.php

then the whole site get messed up



Thanks for your help ^^

Edited by skeddles, 28 March 2009 - 11:04 AM.


#4 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 28 March 2009 - 11:44 AM

QUOTE
you can go to user/username, and it'll direct you to homepage.php?u=username, and if you put /edit at the end, then you can go into edit more, which I wanted,


Are you saying the url in the address bar of the browser is actually changing? If so, that's not in your .htaccess instruction. Which means you've got something else going on somewhere. This may simply be a difference in lingo. There is no such thing as a "transparent" redirect. There are redirects, which are NOT transparent because the address bar changes, and there are URL Rewrites, where the address bar doesn't change but the info is pulled from another place. That's not a redirect, but a rewrite.

QUOTE
the only problem now is that it doesn't work if you dont put domain.com/user/username/ (with a slash at the end)


The Regular Expression way to do this is to enclose the character or characters inside Parens, then immediately follow the closing parens with a question mark. eg if you wanted a query to test true whether a forward slash character was present or not it would look like /something/something(/)?

A warning however. If you're using a full blown wildcard such as (.*) you may need to change this to narrow in on types of characters. eg [a-zA-Z]{4-9} to match upper and/or lowercase letters from 4 to 9 characters in total length or even something like ([a-zA-Z0-9]+) to match any letter or number characters of any string length, but excluding any special characters like slashes, dashes, spaces, @, etc.

In other words, once you think you have something working make sure you test it with the funkiest possible username your internal systems allow.

#5 skeddles

skeddles

    HR 1

  • Members
  • Pip
  • 7 posts

Posted 28 March 2009 - 12:42 PM

CODE
RewriteRule ^user/([a-zA-Z0-9]+)/([a-zA-Z0-9]+) /homepage.php?u=$1&m=$2 [NC]


That's what I tried, and it then works only when there are letters after the slash after the username, else you get a 404
user/username
user/username/

user/username/sdfsdf
user/username/edit


CODE
RewriteRule ^user/(.*)(/)?(.*) /homepage.php?u=$1&m=$2 [NC]

This makes it so it only works without the slash
user/username
user/username/
user/username/edit


My usernames have case insensitive letters, numbers, and underscores/dashes, but I don't know the syntax for that




So I guess I want a rewrite for this
CODE
RewriteRule ^register /register.php [NC]

but I get 500 error, is something wrong with it?

#6 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 28 March 2009 - 02:57 PM

QUOTE
hat's what I tried, and it then works only when there are letters after the slash after the username


As it should. That's what the regex instruction says after all!

QUOTE
This makes it so it only works without the slash


That's the danger of using a full-blown wildcard with a conditional statement. Which is why I warned against it above.

QUOTE
My usernames have case insensitive letters, numbers, and underscores/dashes


And that's it? No other special characters that need to be accounted for? And only only need to account for the exact string of "edit" (eg /user/username/edit) after the username?

If all of that's true I think I'm getting closer to getting on the same page with you. You'll need two rewrite rules, one for the /edit/ that comes first and one for the /user/, where both allow for letters of any capitalization, numbers hyphens and underscores in the username field. These requirements would leave us with:

CODE
RewriteRule ^user/([a-zA-Z0-9_-]+)/edit(/)?$ /homepage.php?u=$1&m=edit [L]
RewriteRule ^user/([a-zA-Z0-9_-]+)(/)?$ /homepage.php?u=$1 [L]


The [L] in there is quite important to keep the 2nd rewrite rule from firing when the first matches.


#7 skeddles

skeddles

    HR 1

  • Members
  • Pip
  • 7 posts

Posted 01 April 2009 - 04:24 PM

QUOTE(Randy @ Mar 28 2009, 03:57 PM) View Post
As it should. That's what the regex instruction says after all!
That's the danger of using a full-blown wildcard with a conditional statement. Which is why I warned against it above.
And that's it? No other special characters that need to be accounted for? And only only need to account for the exact string of "edit" (eg /user/username/edit) after the username?

If all of that's true I think I'm getting closer to getting on the same page with you. You'll need two rewrite rules, one for the /edit/ that comes first and one for the /user/, where both allow for letters of any capitalization, numbers hyphens and underscores in the username field. These requirements would leave us with:

CODE
RewriteRule ^user/([a-zA-Z0-9_-]+)/edit(/)?$ /homepage.php?u=$1&m=edit [L]
RewriteRule ^user/([a-zA-Z0-9_-]+)(/)?$ /homepage.php?u=$1 [L]


The [L] in there is quite important to keep the 2nd rewrite rule from firing when the first matches.


Thanks a lot, that works perfectly! My site's workin' great.

Now my only problem is static rewrites.

I have a couple pages, like /register.php, that I just want to write like /register.

But somethings definitely wrong:

Here's my code:
CODE
RewriteRule ^register$ /register.php [L]


When I try to go there, I get a 404 page, but not even the one I specified, one from my host.

If I change the string like,
CODE
RewriteRule ^registerplz$ /register.php

Then it works, so it's not my code

Also, I still get the same thing if I remove that whole line, going to domain.com/register, but If I just do something random like domain.com/register234234 I'll at least get the right 404 page(the one I set).

Did I accidentally set something wrong permanently? I was playing around with redirects/rewrites earlier, and some didn't work.

If you have any idea what's going on, then I'd appreciate it.

#8 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 01 April 2009 - 06:19 PM

You'll have to speak with your host about that one most likely, assuming of course you have no other conflicting rules in your .htaccess. It's quite possible that there may be something deeper in the apache configuration files than you can see or do anything with. If there is, it's going to override your .htaccess attempts.

It's a guess, but this is possibly indicated by the appearance of a 404 page that is not yours, as if the server is looking for something totally outside of your hosting space.

Or since it works with text that is close to but not quite your "register" wish, you might simply use a slight variation that does work.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

We are now a read-only forum.
 
No new posts or registrations allowed.