Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite Question Regarding Domain Names

         

rcrod83

6:44 pm on Nov 18, 2008 (gmt 0)

10+ Year Member



Hi,

I've been going in circles with this, and it's driving me insane. I've tried so many codes, some work - sort of, but not how I want it.

What I'm trying to do is take the URL example.com/domain.com and redirect it to www.example.com/verify.php?i=domain.com

The problem I am having is that, although it works, the ".com" part gets left off. I also cannot figure out how to allow it to accept http:// or ftp:// or https:// (the script will remove them).

Any help?

Thanks!

jdMorgan

10:39 pm on Nov 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...how to allow it to accept http:// or ftp:// or https:// (the script will remove them).

Ermm.... What script?

Please post your best-effort code as a basis for discussion.

Thanks,
Jim

maxed

5:57 am on Nov 19, 2008 (gmt 0)

10+ Year Member



I think what you mean from the question is: how do i do a rewrite from example.com/value to example.com/verify.php?i=value

If so this should work:
# Internally rewrite
RewriteRule ^([A-Za-z0-9:\./]+)$ verify.php?i=$1 [L]

jdMorgan

3:10 pm on Nov 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Stop the infinite rewrite loop, and speed it up:

# Internally rewrite
RewriteCond $1 !^verify\.php$
RewriteRule ^([a-z0-9:\./]+)$ verify.php?i=$1 [NC,L]

This is almost the simplest solution possible. But it will rewrite requests for images, CSS and JavaScript files robots.txt, etc. to the script as well -- Probably not what's wanted.

Also, note that this is an internal rewrite, as it likely should be, rather than an external redirect, which upon receiving a request for a "friendly" URL send a redirect response to the client, giving it the /verify.php URL, and telling it to ask again for the resource it requested using that new URL in a new (second) HTTP request.

By contrast, an internal rewrite simply says, "If a request is received for URL "x", serve the contents from server filepath "y".

Note the distinction: An external redirect is a URL replacement requiring a second HTTP transaction between the client and the server, while an internal rewrite is a URL-to-filepath translation occuring within the context of the initial HTTP transaction. Mod_rewrite can do either, depending on the syntax of the rule you provide.

Jim

rcrod83

7:26 pm on Nov 19, 2008 (gmt 0)

10+ Year Member



Thanks for the all the responses.

Basically, our verify.php script will verify if the domain name is registered, and if it is, it adds it to our database (the domains are owned by our clients).

The reason we want a "simple" URL is because it makes it faster for us.

Sort of like #*$!/aol.com

In reference to the http/https comment I made, I was stating that the mod_rewrite would/should accept http:// and [,...] as our verify.php script is capable of eliminating those strings before it checks.

I still haven't found a solid code. I might have to hire a pro or something.

maxed

9:30 pm on Nov 19, 2008 (gmt 0)

10+ Year Member



I think you should use some kind of identifier as well, to check if the value begins with [www....] or [www....] so that it stops rewriting unwanted paths to images etc.

jdMorgan

11:01 pm on Nov 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or just something simple like using this kind of URL: example.com/users/user-domain.com

That would be a very simple fix, and avoid all possible conflicts with other existing files or script URLs.

The problem isn't with the code, it's with designing the URLs so that mod_rewrite can reliably detect them and handle them properly without having conflicts with 'real' pages and files.

Jim

rcrod83

12:39 am on Nov 20, 2008 (gmt 0)

10+ Year Member



I think everyone is right.

I think we'll go with example.com/verify/domain.com

Now I have to write new code to handle it instead.

g1smd

1:53 am on Nov 23, 2008 (gmt 0)

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



To be clear here, are you sure what you want; a redirect or a rewrite?