I'm making a very small project, whereas normally I would use a PHP framework that handles this for me, I don't want the unneeded clutter of a framework. I have this structure:
-> assets
-> css/etc
-> pages
-> api.htm
-> scramble.htm
-> unscramble.htm
-> structure
-> header.htm
-> footer.htm
-> index.php
All of these files are in a directory themselves, example.com/example/scrambling/
So, to access my files, normally I would have to access example.com/example/scrambing/pages/api.htm
for example - but I want all of the page loading to be handled through index.php.
My goal is to access the file above by simply going to example.com/example/scrambling/api
I found some questions on how to achieve this with .htaccess, but none of them are working for me. They always result in an infinite loop, and getting redirected to /example/scrambling/pages/index/pages/index/pages/index/pages/...
- I'm not really sure how to go about solving this issue.
My current .htaccess file is this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?f=$1
and I try to access the page name by echo $_REQUEST['f'];
How can I make the .htaccess file not infinitely redirect me?
Try this, this will definitely work.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^([^/]+)$ index.php?f=$1 [L,QSA]
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.