tags:

views:

26

answers:

2

I'd like to rewrite form submissions to clean URLs, so that example.com/search/go?term=foo becomes example.com/search/foo

How do I do this?

A: 

You can change the URL that is called in the action attribute of the form element in HTML. Alternatively, you could set it in an OnClick JavaScript event handler on a button.

You don't need mod_rewrite and .htaccess to accomplish this.

Though, you could use mod_rewrite to redirect everything that's not a document to an index controller script and do the translation there.

RewriteEngine on
RewriteBase /
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php

That's how Zend Framework does it, and actions look like example.com/search/foo instead of example.com/search/go?term=foo. Of course, search would need to be a script.

Marcus Adams
A: 

Use JavaScript:

<input type="text" id="search_term" />
<input type="button" value="Search" onclick="goSearch()" />

<script type="text/javascript">
    function goSearch() {
        var term = document.getElementById("search_term");
        window.location = "http://example.com/search/" + escape(term);
    }
</script>

URL encode the query string, and redirect to the desired path.

Dolph