Forum Moderators: phranque

Message Too Old, No Replies

htaccess redirect

         

nimonogi

7:47 pm on Jun 18, 2010 (gmt 0)

10+ Year Member



i want every possible compilation that starts with dir "/uk/" to redirect like the following example:

From:

domain.com/uk/
domain.com/uk/file.php
domain.com/uk/directory/file.php
domain.com/uk/directory/directory2/file.php


To:

domain.com/?step1=1&step2=2
domain.com/file.php?step1=1&step2=2
domain.com/directory/file.php?step1=1&step2=2
domain.com/directory/directory2/file.php?step1=1&step2=2


Thanks in advance!

g1smd

8:15 pm on Jun 18, 2010 (gmt 0)

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



Why are you making your URLs more complex, directing to a different, longer, URL?

What is the URL that you really want users to see and use out on the web?

What is the location inside the server where the content actually resides?

nimonogi

8:37 pm on Jun 18, 2010 (gmt 0)

10+ Year Member



Actually i'm trying to make my URLs more simple.

When the visitors click at (ex. from a link outside my website) domain.com/uk/file.php i want to be redirected to domain.com/directory/file.php?step1=1&step2=2

step1=1&step2=2 are coded to parse specific values.

g1smd

9:04 pm on Jun 18, 2010 (gmt 0)

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



If you redirect the user, they will see and use the longer, less simple URL.


Are you sure you want a redirect? Would a rewrite be a better option?

nimonogi

9:54 pm on Jun 18, 2010 (gmt 0)

10+ Year Member



I'm not sure about the rewrite.
If the "?step1=1&step2=2" is entered once, it is stored in session, and then its not necessary.

nimonogi

1:42 pm on Jun 21, 2010 (gmt 0)

10+ Year Member



*bump*

jdMorgan

2:57 pm on Jun 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because you are trying to "map" search-friendly URL requests to script filepaths+query_strings on your server, this is an internal server-side URL-to-filepath rewrite, not a external client-side URL-to-URL redirect.

See the thread Changing Dynamic URLs to Static URLs [webmasterworld.com] in our Apache Forum Library and the resources cited in our Apache Forum Charter to get started. Your application is simpler than the example in that thread, so you can likely simplify the example code quite a bit.

Other related-topic threads should be findable with a site search for "rewrite static URL dynamic filepath" and similar phrases.

Beware of the commonly-encountered problem with putting variables into your URL-path: It is the browser that resolves relative links on page to the canonical full URL that it must request. Therefore, all links on your pages must be server-relative or canonical. For a concrete example, you must use the forms <img src="/images/logo.gif"> or <img src="http://example.com/images/log.gif"> and not <img src="images/logo.gif"> or <img src="../images/logo.gif"> for images, CSS files, and external JavaScript files referenced in your HTML.

Jim