简体   繁体   English

mod_rewrite删除查询字符串并替换为“文件夹”名称

[英]mod_rewrite to remove query string and replace with 'folder' names

So i already have some rewrites in place, but in truth i didn't write them :( i'd love to understand them rather than just asking for help. But i know nothing about them and i don't feel i have time spending hours learning :( 所以我已经有一些重写了,但是实际上我没有写它们:(我很想理解它们,而不是仅仅寻求帮助。但是我对它们一无所知,而且我不觉得我有时间在花时间学习时间:(

Anyway i'd like to turn 反正我想转

http://wouldyourathers.co.uk/?qid=1231

into: 变成:

http://wouldyourathers.co.uk/question/1231

For me qid is rather ugly. 对我来说,qid相当丑陋。 Lets just say i could easily change this to ?question but i still feel its not pretty. 可以说我可以轻松地将其更改为“问题”,但我仍然觉得它不漂亮。

Only problem is i already have rewrites in place with: 唯一的问题是我已经使用以下方法进行了重写:

RewriteCond %{REQUEST_URI} !dispatch\.php$
RewriteCond /var/www/wyr/docroot%{REQUEST_FILENAME} !-f
RewriteRule ^(/.*)$ /dispatch.php?url=$1 [L,QSA]
RewriteRule ^x\.!dispatch\.php([^b]+)!dispatch\.php$ !dispatch\.php [L,NE]

This will point any request from my server to my dispatch.php and in here i basically mess around with the url's to display them in a sexy way. 这会将来自我的服务器的任何请求指向我的dispatch.php,在这里,我基本上搞乱了url,以一种性感的方式显示它们。 But i'm stumped as to how i can edit the query. 但是我很困惑如何编辑查询。 Once inside the dispatch file i can edit this and do the code i need to effect the data calls. 进入调度文件后,我可以对其进行编辑,并执行执行数据调用所需的代码。

Thanks (even if this is longer than needs be) 谢谢(即使这比需要的时间更长)

在其他规则之前,您可以尝试添加以下内容:

RewriteRule ^/question/([0-9]+)$ /?qid=$1 [L,QSA]

Right now, without any changes to your rules when you go to http://wouldyourathers.co.uk/question/1231 you should have /question/1231 in $_GET['url'] in dispatch.php script. 现在,转到http://wouldyourathers.co.uk/question/1231时,您的规则没有任何更改,您应该在dispatch.php脚本的$_GET['url']中拥有/question/1231

You could parse that url with PHP and recover your question id: 您可以使用PHP解析该网址并恢复您的问题ID:

$parts = explode('/', $_GET['url');
if ($parts[1] == 'question') {
    $question_id = $parts[2];
    // you could even do $_GET['qid'] = $parts[2];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM