Forum Moderators: phranque

Message Too Old, No Replies

Pls Help.Rewrite question

Rewrite question

         

nathan79

4:30 pm on Nov 23, 2005 (gmt 0)

10+ Year Member



Hi,
I have this is my .conf file:

RewriteRule /Display\.html(.+) [example...] [R]
RewriteRule ^/index\.html$ [example...]

Whenever i try accessing the first URL i.e.,
[example...]
It gives me the second URL i.e.:http://example/RTindex.html/
How do i avoid this?

Thanks
Nathan

jdMorgan

5:20 pm on Nov 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You cannot access a query string using RewriteRule; Use RewriteCond instead, and back-reference the matched value with %1 rather than $1:

RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule /Display\.html$ http://example.com/Ticket/DisplayTicket.html%1 [R=301,L]
RewriteRule ^/index\.html$ http://example.com/RTindex.html/ [R=301,L]

Jim

nathan79

6:35 pm on Nov 23, 2005 (gmt 0)

10+ Year Member



Now when i access:
http://example.com/Ticket/Display.html?id=4935, it gives the URL:
http://example.com/Ticket/DisplayTicket.htmlid=4935?id=4935

How do i avoid this?

Thanks
Nathan

jdMorgan

7:11 pm on Nov 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know. You have not described what kinds of URLs you want to redirect, and what kinds of URLs you don't want to redirect. If you want to use mod_rewrite, you need to be very, very specific, and you should not start coding until the problem is thoroughly-described.

Jim

nathan79

7:35 pm on Nov 23, 2005 (gmt 0)

10+ Year Member



I am sorry Jim. Let me explain what i am trying to do:
We are using the apache's NTLM module to do the single sign-on. This module requires a valid user and it gives a authentication pop-up (since its in the internet domain) when we accessed the index page (index.html). To avoid this pop-up from appearing (and make it available in the intranet domain) what we did was redirected the index.html to RTindex.html(
-exact replica of index.html)page:
RewriteRule ^/index\.html$ http://example.com/RTindex.html/ [R=301,L]

This worked out when a user simply typed http://example.com/ in his browser and it avoided the pop-up but soon we realized that emails that were sent to users to access our application also gave a URL:
http://example.com/Ticket/Display.html?id=4935.

When a user clicks on the link given in the mails it gives a pop-up which we want to avoid and so the reason for using the other redirect:
RewriteRule /Display\.html$ http://example.com/Ticket/DisplayTicket.html%1 [R=301,L]

So i wanted to redirect the URL http://example.com/Ticket/Display.html?id=4935 so that i can avoid the pop-up.

Thanks
Nathan

nathan79

7:55 pm on Nov 23, 2005 (gmt 0)

10+ Year Member



I am sorry for not mentioning this previously:
DisplayTicket.html is the exact replica of Display.html. Since te rewrite for index.html worked, i thought the rewrite for Display.html should work too.

Thanks
Nathan

jdMorgan

10:34 pm on Nov 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, well I'm still not sure what URL you want to redirect *to* but maybe this will work better:

RewriteCond %{QUERY_STRING} .+
RewriteRule ^Ticket/Display\.html$ http://example.com/Ticket/DisplayTicket.html [R=301,L]

Also, be aware that you may be able to use a 'silent' rewrite, as opposed to a redirect:

RewriteCond %{QUERY_STRING} .+
RewriteRule ^Ticket/Display\.html$ /Ticket/DisplayTicket.html [L]

This has the advantage that the user never sees the address bar change, but can bring in complications, depending on your authentication script and other factors.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

nathan79

3:48 pm on Nov 28, 2005 (gmt 0)

10+ Year Member



Hi Jim,
I want to redirect my URLS to http://example.com/Ticket/DisplayTicket.html?id=4935. I tried what you suggested but it keeps throwing me to the RTindex.html page.

Does that help?

Thanks
Ahalya

jdMorgan

6:55 pm on Nov 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please provide:

  • Multiple examples of the URLs that will be requested by the browsers or search engine robots.
  • The URL-paths of the resources (existing files or scripts) on the server that you want to correspond to those requested URLs.

    I am not at all sure whether you are trying to publish static URLs and server them with dynamic content, or vice-versa...

    Jim

  • nathan79

    8:19 pm on Nov 29, 2005 (gmt 0)

    10+ Year Member



    (1)The following are examples of URLs given in the emails, which need to be redirected:
    ******************************************************
    1.http://example.com/Ticket/Display.html?id=4935
    2.http://example.com/Ticket/Display.html?id=4938
    3.http://example.com/Ticket/Display.html?id=123
    The value of the "id" is dynamic. The above html file(Display.html) is present in the location /usr/local/rt/local/html/Ticket/.

    I want to redirect the above example URLS to the following URLS.The html file(DisplayTicket.html) is present in the location /usr/local/rt/local/html/Ticket/. Again the value of id is dynamic.

    http://example.com/Ticket/DisplayTicket.html?id=4935
    http://example.com/Ticket/DisplayTicket.html?id=4938
    http://example.com/Ticket/DisplayTicket.html?id=123
    ******************************************************
    2. The URLs which are given in the browser which need to be redirected are:
    http://example.com/
    [test.example.com...]
    [test_help.example.com...]

    The location of the index file(index.html) is present in the location: /usr/local/rt/local/html/.

    The URLS in point(2) need to be redirected to:
    http://example.com/RTindex.html. The location of this html file is present in /usr/local/rt/local/html/.
    ******************************************************

    Thanks
    Nathan

    jdMorgan

    8:46 pm on Nov 29, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    It may just be that by habit, I write code for use in .htaccess by default. I see several hints that your code is for use in httpd.conf.

    In that case, you'll need a leading slash on the RewriteRule pattern:


    RewriteCond %{QUERY_STRING} id=[^&]+
    RewriteRule [b]^/T[/b]icket/Display\.html$ http://example.com/Ticket/DisplayTicket.html [R=301,L]

    I also made this code more specific, requiring a queery string of "id=" followed by one or more characters other than an ampersand.

    If this doesn't work, I have no clue why... :(

    Jim

    nathan79

    10:07 pm on Nov 29, 2005 (gmt 0)

    10+ Year Member



    Jim,
    That didn't seem to work. I am going to look into it more and will post if i am able to solve this problem. Thanks a lot Jim, I was atleast able to understand Rewrite engine more after your posts.
    Can you tell me if this code will work?

    RewriteCond %{HTTP_REFERER}
    ! ^Ticket/DisplayTicket\.html$ [NC]
    RewriteRule ^/index\.html$ [webtlh01...] [R=301,L]

    Basically i am trying to avoid the RTindex.html page from appearing when Ticket/DisplayTicket.html is accessed.

    Thanks,
    Nathan

    nathan79

    10:09 pm on Nov 29, 2005 (gmt 0)

    10+ Year Member



    The webtlh01 should be example.com, sorry abt that

    RewriteRule ^/index\.html$ http://example.com/RTindex.html/ [R=301,L]