表单操作得+现代重写 [英] Form action GET + Mod Rewrite
问题描述
我很抱歉,如果我重复一个问题,但我似乎无法来解决这个看着其他答案:(。
我有一个GET操作的形式:
<形式的行动=标签的作用=形式的方法=获得>
其中包含一个名为一个搜索输入Q
我要的是,当我提交表单,在导航栏中显示的URL是:
的http://本地主机/网络/标签/礼服
相反,
的http://本地主机/网络/标签Q =礼服
在我的.htaccess我有
重写规则^标签/([0-9A-Z] +)/ $的index.php?标记= $ 1 [L]
当我直接访问哪些工作正常:
的http://本地主机/网络/标签/礼服
我要的是形式要带我去这个干净的URL,而不是使用的?q =导航栏中的参数。
有什么建议?
我的.htaccess的简化版本是:
的ErrorDocument 404的http://本地主机/网络/#404
RewriteEngine叙述上
重写规则^的index.html的index.php [L]
###标签
?重写规则^标签/([0-9A-Z] +)/ $的index.php seccion =家庭及放大器;标签= $ 1 [L]
###用户资料
?重写规则^([0-9A-Z] +)/ $的index.php seccion =轮廓和放大器;用户= $ 1 [L]
您现有的规则之前添加这些额外的规则:
#外部重定向从实际的URL pretty的1
?的RewriteCond%{THE_REQUEST} \ S / +网/标签\ Q =([^ \ S&功放;] +)[NC]
重写规则^ /网页/标签/%1? [R = 302,L]
更新:您的完整的.htaccess: 注:/失踪了。现在,它应该工作。
ErrorDocument的404网/#404
RewriteEngine叙述上
的RewriteBase /网络/
#外部重定向从实际的URL pretty的1
的RewriteCond%{} THE_REQUEST /标签/ \ Q =([^ \ S&安培] +)?[NC]
重写规则^标签/%1? [R = 302,L]
重写规则^指数\ html的$的index.php [L,NC]
###标签
?重写规则^标签/([0-9A-Z] +)/ $的index.php seccion =家庭及放大器;标签= $ 1 [L,NC,QSA]
###用户资料
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
?重写规则^([0-9A-Z] +)/ $的index.php seccion =轮廓和放大器;用户= $ 1 [L,NC,QSA]
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]
这篇关于表单操作得+现代重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!