I'm sorry if I'm repeating a question, but I can't seem to solve this looking at other answers :(
I have a FORM with GET action:
<form action="tag" role="form" method="get">
Which contains a search input named "q"
What I want is that when I submit the form, the URL displayed in the navigation bar is:
http://localhost/web/tag/dress
Instead, of
http://localhost/web/tag?q=dress
In my .htaccess I have
RewriteRule ^tag/([0-9a-z]+)/?$ index.php?tag=$1 [L]
Which works fine when I access directly to:
http://localhost/web/tag/dress
All I want is the form to take me to this clean URL instead of using the ?q= parameter in the navigation bar.
Any suggestions?
A simplified version of my .htaccess is:
ErrorDocument 404 http://localhost/web/#404
RewriteEngine on
RewriteRule ^index.html index.php [L]
###TAG
RewriteRule ^tag/([0-9a-z]+)/?$ index.php?seccion=home&tag=$1[L]
###USER PROFILE
RewriteRule ^([0-9a-z]+)/?$ index.php?seccion=profile&user=$1 [L]
Add this additional rule before your existing rule:
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+web/tag\?q=([^\s&]+) [NC]
RewriteRule ^ /web/tag/%1? [R=302,L]
UPDATE: Your complete .htaccess: NOTE: "/" was missing. Now it should work.
ErrorDocument 404 web/#404
RewriteEngine on
RewriteBase /web/
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /tag/\?q=([^\s&]+) [NC]
RewriteRule ^ tag/%1? [R=302,L]
RewriteRule ^index\.html$ index.php [L,NC]
###TAG
RewriteRule ^tag/([0-9a-z]+)/?$ index.php?seccion=home&tag=$1 [L,NC,QSA]
###USER PROFILE
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-z]+)/?$ index.php?seccion=profile&user=$1 [L,NC,QSA]
I wonder if I am forced to do this with javascript?
Something like:
$('.search-form').submit(function (event) {
var tag = $('#q').val();
window.location='tag/'+tag;
return false;
});