简体   繁体   中英

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. 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. 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.

You could parse that url with PHP and recover your question id:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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