Forum Moderators: phranque

Message Too Old, No Replies

Url rewrite help wanted.please help

URL redirect -Tried many options but doesnt work..

         

mathew2009in

10:44 am on Nov 22, 2009 (gmt 0)

10+ Year Member



Hi all

I am new in redirect.htaccess and cannot understand much commands of it.

what I need is rewrite command for example.com/data?url=www.google.com to example.com/google.com

I know its pretty simple for you guys but I couldnt find a solution using my knowledge.

please help me to resolve the same.

thank you all

Mathew

g1smd

1:31 pm on Nov 22, 2009 (gmt 0)

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



I am surprised that you can't find any examples.

This question, or a variant of it, is asked almost every day; and three times in just the last 24 hours.

mathew2009in

5:28 pm on Nov 22, 2009 (gmt 0)

10+ Year Member



yeah I agree

and I am able to redirect

like this
Options +FollowSymLinks
RewriteEngine on
RewriteRule url/(.*) links.php?domain=$1 [L]

I am able to get result by typing example.com/url/google.com using above command. but when i access through example.com/data?url=google.com the browser url is not changing to example.com/google.com.

like compete.com or quantcast.com

any help?

THanks

Mathew

jdMorgan

5:53 pm on Nov 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need a second rule -- in this case an external redirect to do that.

This new rule will also need to check to be sure that it is a client requesting the "links.php" path, and that the path is not being requested as a result of your first rule above. If this check is not done, then the result will be an infinite rewrite/redirect loop.

I've made the code a bit more robust, as you've got some potential here for malicious abuse.


Options +FollowSymLinks
RewriteEngine on
#
# Externally redirect (only) direct client requests for links.php?domain=<domain> to /url/<domain>
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /links\.php\?domain=http://(www\.)?([^/\ ]+)[^\ ]*\ HTTP/
RewriteRule ^links\.php$ http://www.example.com/url/%2? [R=301,L]
#
# Internally rewrite "url/" requests to exit-link-tracking script if referer is my site (or blank)
RewriteCond %{HTTP_REFERER} ^((www\.)?example\.com.*)?$
RewriteRule ^url/(.*)$ links.php?domain=$1 [L]

[added] Corrected as noted below. [/added]

Jim

[edited by: jdMorgan at 1:28 am (utc) on Nov. 23, 2009]

mathew2009in

6:12 pm on Nov 22, 2009 (gmt 0)

10+ Year Member



THanks for your help

but still I am not able to see the result like what I was thinking... the URL is not rewriting and gettting internal server error

regards

Mathew

mathew2009in

7:05 pm on Nov 22, 2009 (gmt 0)

10+ Year Member



well I have tried what I can but still not redirecting to example.com/request.com.

can you give me complete code which I only need to put directly to htaccess file?. I have no grip on htaccess file scripts.

thanks

Mathew

jdMorgan

1:27 am on Nov 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I made a few corrections to the code posted above. However, it's up to you to get this working, and more to the point, to use this exercise to learn about .htaccess coding. This is a discussion forum, and not a free coding service... See our Apache Forum Charter for more information.

If you get server errors, check your server error log -- some good information in there, usually.

Jim

mathew2009in

7:11 am on Nov 23, 2009 (gmt 0)

10+ Year Member



Thank you Verymuch JdMorgan........

I lost three four days to find a solution for my requirement..I was able to do all other redirections using examples provided in this forum and other websites but for this case not.

I have invested 5-6 months for my upcoming site whcih is launching shortly.

this is a free site offering Pageviews,page visits,visitors,unique visitors,average stay,pages per visit,site details,backlinks,domain info,server info etc.

so I dont have enough time to spend for redirection. this is the reason why I requested the complete code.

one more question if I need to avoide "url" directory then how this will work I have removed "url/" from above code but it doesnt update sites as it shows only first domain info...

Thanks again

Mathew

jdMorgan

8:56 pm on Nov 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The examples are sort of "wandering away" from the code here.

Please re-state your exact requirements, with correct example URLs and filetpaths. I don't know, for example, where "data?url=" came from -- It just sort of appeared in the discussion. I also don't know what you mean by "avoid 'url' directory."

These things usually go much easier if you state the specific URL-path requested by the browser and a specific disposition for that request; Either it should be re-written to a specific server filepath, or it should be redirected to a different specific URL. We need all the details, and solid, consistent examples.

Jim

mathew2009in

8:27 am on Nov 28, 2009 (gmt 0)

10+ Year Member



Hi Jim

Sorry for the confusion...

According to your current above code the browser address will look like:-
www.example.com/url/google.com

I want

www.example.com/google.com

regards

Mathew

jdMorgan

4:00 pm on Nov 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, you can use anything for "url" that you like, but you cannot use nothing... Otherwise, consider what happens when a request arrives at your server for any 'normal' file, say "/robots.txt".

If you don't put *some* kind of prefix on the exit-tracking URLs, then a request for /robots.txt will be exit-tracked and redirected to http://www.robots.txt/ -- Every file on your site will become an "exit URL" and your site will cease to function.

Jim

mathew2009in

4:47 pm on Nov 28, 2009 (gmt 0)

10+ Year Member



Hi JIm

BUt tel me then how [other DNS information sites like compete.com or quantcast.com] works?

if you type <dns-chscker-site>.com/google.com then it works well and get results what you search for.
This is the same way which I also looking...when some one search my site www.example.com/google.com then he should get result. in short instead of www.example.com/url/google.com to www.example.com/google.com....

Best

Mathew

[edited by: jdMorgan at 5:07 pm (utc) on Nov. 28, 2009]
[edit reason] example.com [/edit]

mathew2009in

4:49 pm on Nov 28, 2009 (gmt 0)

10+ Year Member



oops some typo error please read #*$!/google.com

instead of #*$!/google.com

mathew2009in

4:50 pm on Nov 28, 2009 (gmt 0)

10+ Year Member



oh ho why #*$! dot com is not acceptable to this site?

mathew2009in

4:51 pm on Nov 28, 2009 (gmt 0)

10+ Year Member



<snip>

[edited by: jdMorgan at 5:04 pm (utc) on Nov. 28, 2009]
[edit reason] No specific domains, please. [/edit]

mathew2009in

5:34 pm on Nov 28, 2009 (gmt 0)

10+ Year Member



sorry I don't know that...

jdMorgan

5:36 pm on Nov 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are a few ways to do this: Make a list of all URLs on your site, and exclude those URLs from being rewritten to the domain-info script. This can be made easier if you move all non-well-known files into subfolders, leaving only your index page, robots.txt, sitemaps, and webmaster verification/validation files in your root directory (where they are required to be). That's the safest way to do it, and the easiest to maintain.

Another way to do it is to 'filter' based on all known filetypes on your site. That is, don't rewrite to the script if there is no filetype, or if the filetype is .html, .php, .jpg, .gif, .png, .ico, .css, .js, .mp3, .avi, etc., etc. -- But you need a *complete* list. All other period-delimited strings at the end of requested URL-paths will then be assumed to be domain TLDs, and will be rewritten to your script.

You'll have to research this and determine the best way for your site, considering the complexity of the exclusion and ease of long-term maintenance.

Jim

mathew2009in

3:31 am on Dec 6, 2009 (gmt 0)

10+ Year Member



JIm

I have another problem...actually i was busy on final touch on my new site launch..everything was complete and when I use forms to submit then I am getting 404 error.but if you enter in browser it works fine..what may be the problem?

here is my form
<form name="backlinkform" action="links.php" method="get">
<label>Domain Name
<input name="domain" type="text" value="" size="45" width="300px" height="20px">
</label>
<label>
<input type="submit" value="Submit" id="submit" >
</label>
</form>

jdMorgan

4:16 pm on Dec 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest you use a server-relative path for "action=" instead of a page-relative path. That is, start the path with a slash, and then specify the filepath "all the way down" from your documentroot.

Jim

mathew2009in

4:31 pm on Dec 6, 2009 (gmt 0)

10+ Year Member



can you post an example?

mathew

mathew2009in

6:21 pm on Dec 6, 2009 (gmt 0)

10+ Year Member



ok I got...I think I can manage

thanks

Mathew

g1smd

6:33 pm on Dec 6, 2009 (gmt 0)

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



action="[b]/[/b]the/path/to/your/links.php"

mathew2009in

1:07 am on Dec 7, 2009 (gmt 0)

10+ Year Member



ok it is now working but needs to remove line "RewriteCond %{HTTP_REFERER} ^((www\.)?example\.com.*)?$"

now i am facing problem with css. css files are'nt loading! if you check the path it shows /url/style.css but there isnt any directory called url.

what may be the reason? why I need to remove "RewriteCond %{HTTP_REFERER} ^((www\.)?example\.com.*)?$"

Mathew

jdMorgan

3:15 pm on Dec 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make all of your on-page links just like the one for your 'action' -- Use either a server-rooted URL (starts with a slash and the full filepath) or a canonical URL (http://www.example.com/full-path). Otherwise, the browser will resolve page-relative URLs based on the 'page URL that is showing in its address bar. Since that URL now contains "/url", all relative link URLs will also be resolved as being in that directory.

Jim

mathew2009in

5:43 pm on Dec 7, 2009 (gmt 0)

10+ Year Member



JIm

You are a master........I agree

great this was again time consuming for me till you mention this...wow really works nice

thanks again

Mathew