# Check URL

**URL:** <https://www.ruby-forum.com/t/check-url/188947>\
**Category:** Rails\
**Created:** [May 21, 2010, 12:07am UTC](https://www.ruby-forum.com/t/check-url/188947 "2010-05-21T00:07:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidz101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@davidz101](https://www.ruby-forum.com/u/davidz101)\
**Post date:** [May 21, 2010, 12:07am UTC](https://www.ruby-forum.com/t/check-url/188947/1 "2010-05-21T00:07:18Z")

</div>

Is there a way to do an if/else case to check the URL? for example-

\<% if URL = “[http://www.google.com](http://www.google.com)” %\>

Hi, your URL’s GOOGLE

\<% else %\>

You URL isn’t GOOGLE

\<% end %\>

Of course that method is just a mockup, does anyone know the real  
syntax? Thanks

---

<div class="post-metadata">

**Author:** ![davidz101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@davidz101](https://www.ruby-forum.com/u/davidz101)\
**Post date:** [May 21, 2010, 12:13am UTC](https://www.ruby-forum.com/t/check-url/188947/2 "2010-05-21T00:13:45Z")

</div>

On May 20, 2010, at 3:05 PM, David Z. wrote:

> \<% end %\>
> 
> Of course that method is just a mockup, does anyone know the real  
> syntax? Thanks

\<% if request.url == ‘[http://www.google.com](http://www.google.com)’ %\>  
GOOGLE!  
\<% else %\>  
not google  
\<% end %\>

That’s literally what you’re asking, but not sure if it’s really what  
you want to do. You might be better off checking params[:controller]  
and params[:action] perhaps. Or doing a regular expression match to  
pick up “[http://google.com](http://google.com)” and  
“[http://maps.google.com/q=12345+Maple+St](http://maps.google.com/q=12345+Maple+St)”, etc.

But… in any event, request.url will give you what the browser sees in  
their location bar.

-philip

---

<div class="post-metadata">

**Author:** ![davidz101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@davidz101](https://www.ruby-forum.com/u/davidz101)\
**Post date:** [May 21, 2010, 12:17am UTC](https://www.ruby-forum.com/t/check-url/188947/3 "2010-05-21T00:17:16Z")

</div>

On May 20, 6:12 pm, Philip H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > You URL isn’t GOOGLE  
> > \<% end %\>
> 
> That’s literally what you’re asking, but not sure if it’s really what you want to do. You might be better off checking params[:controller] and params[:action] perhaps. Or doing a regular expression match to pick up “[http://google.com](http://google.com)” and “[http://maps.google.com/q=12345+Maple+St](http://maps.google.com/q=12345+Maple+St)”, etc.
> 
> But… in any event, request.url will give you what the browser sees in their location bar.
> 
> -philip

YUP! sweet dude, thanks 😃
