简体   繁体   中英

mod_rewrite RewriteRule with REQUEST_URI

How can I specify the mod_rewrite RewriteRule to use the REQUEST_URI as the pattern it checks, rather than the full directory path of the file?

Currently, I'm able to pass the URI through a GET param, like so:

(.+) topicview.php?topicname=%{REQUEST_URI}

But I want the (.+) Pattern to match the REQUEST_URI itself, rather than the directory path, which is ugly and looks like data/2/2/3233/user/21212/morestuff/more/topicview.php

As per my answer to your other question at Network Solutions hosting URL looks weird for Apache server try using a RewriteCond instead to capture the value you want:

RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule . topicview.php?topicname=%1 [L]

Note the %1 rather than $1 which allows you to use values captured in the RewriteCond.

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