简体   繁体   中英

.htaccess rewrite rule from dynamic url to static url (no querystring)

I have a page with a form - http://www.example.com/results/index.php . I need to make it so that the form can be accessed from the url http://www.example.com/results/[anystring] . That is, the user sees the http://www.example.com/results/[anystring] url in the browser address bar but they are seeing the contents of the page http://www.example.com/results/index.php from the server. The "anystring" piece will be used by the page's form and if it's in a list of extpected strings, then the form will show, and the "anystring" will be a value of a hidden field. I know how to do the PHP part of this - use the "anystring" in the form if it is in a list of expected string. I don't know how to do the rewrite from a url with a dynamic piece - http://www.example.com/results/[anystring] - to access a static page - http://www.example.com/results/index.php .

So far I've got the following which doesn't work:

RewriteEngine On
RewriteBase   /results/
Rewrite Rule (\w+) index.php [L]

Additionally, there are also other urls that need to stay unaffected by this, such as http://www.example.com/results/path/to/other/files.php .

Can someone point me in the right direction?

You are fairly close. You may use this rule in results/.htaccess file:

RewriteEngine On
RewriteBase /results/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

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