dtkvlj5386 2013-11-18 17:33
浏览 31

表格动作GET + Mod Rewrite

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]
  • 写回答

2条回答 默认 最新

  • doucuo4413 2013-11-18 17:36
    关注

    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]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?