从的.htaccess GET变量重定向到URL字符串(.htaccess redirect from GET variable to url string)

   IT问题网   2018-09-18 00:00:00

问 题

我需要重定向

/搜索?关键词= somesearchterm
 

/搜索/ somesearchterm
 

这似乎令人难以置信的基本的,但我一直在敲打我的头靠在了一个小时。

感谢您抽出时间来看看这个。

解决方案

您想实现什么是所谓的"301重定向"与mod_rewrite的。

rewriteengine叙述on
重写规则^ /搜索\?关键词= somesearchterm $ /搜索/ somesearchterm
 

补充定期ex pressions:

rewriteengine叙述on
重写规则^ /搜索\?关键词=(+)/搜索/ $ 1 [r = 301,l]
 

r = 301 表示提供301头重定向,以便在浏览器用户的url发生变化,而→办法不处理任何更多的重写规则,如果此匹配。


如果你想要做相反的 - 换句话说,如果有人去 mysite.com/search/asearchterm 和您想要的网址保持不变,但"幕后"你想让它加载某些服务器脚本,做到这一点:

rewriteengine叙述on
重写规则^ /搜索/(.+)/search.php\keywords=$1 [l]
 

标签:变量定向字符串



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

PHP:为每个用户使用htaccess的动态子域(PHP : dynamic sub domains for each user using htaccess)

problem is it possible to createdynamic sub domains for e ...

的.htaccess更改网址(.htaccess to change URL)

problem so i have a mvc system setup but it does not gene ...

mod_rewrite的{QUERY_STRING}(mod_rewrite {QUERY_STRING})

problem i'm sure that's been asked zillions times but i c ...

重写规则htaccess的,以匹配特定的文件扩展名(rewriterule in htaccess to match certain file extensions)

problem how can i look for an instance for certain file e ...

PHP或htaccess的进行动态URL页面去404项时,在数据库丢失(PHP or htaccess make dynamic url page to go 404 when item is missing in DB)

problem typical scenario: db items are displaied in pag ...

如何使直接图像访问htaccess的重定向,同时允许嵌入(How to make htaccess redirect on direct image access while allowing embedding)

problem the scenario looks like this, say that i have a w ...

Opencart的.htaccess问题(Opencart .htaccess issue)

problem i'm having similar problem my url is like name.do ...

图像不可读的codeigniter网站?(image unreadable on codeigniter site)

problem (this may belong on serverfault, since apache is ...

如何使用htaccess的改变图像路径?(How to use htaccess to change image paths)

problem i have a html file that has an image: lt;img src ...

为什么DOCUMENT_ROOT比真实路径不同('。')远程服务器上(Why DOCUMENT_ROOT is different than realpath('.') on remote server)

problem with echo realpath('.').'lt;brgt;'; echo dirnam ...

如何从下面的.htaccess重写规则排除特定的文件类型?(How to exclude specific file types from the following .htaccess rewrite rule)

problem how can you exclude specific files types (xml and ...

重定向到特定的网页,如果没有登录 - 的.htaccess(redirect to specific page if not logged in - .htaccess)

problem i am running apache2 and php5 in my windows pc. ...

的.htaccess力PDF下载在Safari(.htaccess Force PDF Download in Safari)

problem i want to force a pdf to download, rather than lo ...

403重定向不工作(403 redirect doesn't work)

problem how to force apache to redirect to a 403 error i' ...

语言重定向与mod_rewrite的(Language Redirect with mod_rewrite)

problem i have a site that is offered in 7 languages. i ...

如何更换的robots.txt用的.htaccess(How to replace robots.txt with .htaccess)

problem i have a small situation where i have ...

htaccess的重定向与变数(htaccess redirection with variables)

problem can someone help me with this what i' ...

PHP /阿帕奇:重写与的.htaccess规则(PHP/Apache: Rewrite rules with .htaccess)

problem i have a bit of a dilemma with mod_rewrite. how d ...

URL重写,PHP模板和$ _GET数组(URL rewriting, PHP templating and the $_GET array)

problem i have an index.php file in the top level with ot ...

不包含给定的字符串的正则表达式匹配的网址(regex match urls NOT containing given set of strings)

problem i need to match all urls that do not contain eith ...