Reputation: 125
I have a HTML form which looks like this:
<form action="process.php" method="get">
<input type="text" id="q" name="q" maxlength="16">
</form>
The process.php spits out some data, that's all working fine. When it has returned the data the URL looks like this:
website.com/process.php?q=banana
I would like to have a cleaner URL like this:
website.com/banana/
Is this possible using .htaccess? Thanks in advance!
Upvotes: 0
Views: 56
Reputation: 785246
Put this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
# external redirect from actual URL to pretty one
#RewriteCond %{THE_REQUEST} \s/+process\.php\?q=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^([^/]+)/?$ /process.php?q=$1 [L,QSA]
Upvotes: 1
Reputation: 2130
I think you're going to have to use method="post" to hide the Query String in the URL. I can't think of any way to dictate the format of the URI when using a form submission, but maybe someone else can come up with something.
Upvotes: 0