How would I go about creating a mod_rewrite that redirects to launch.php?i=/the/url/that/they/want?
-
03-07-2019 - |
Question
So if the user types mydomain.com/dashboard, the document the server actually sends them is /launch.php?i=/dashboard.
The one caveat is that I would like to leave requests for
- /flags
- /people
- /posters
- /css
- /icons
- /images
- /libraries
- /patterns
alone, and they should request the actual folder.
How would I create such a mod_rewrite?
Solution
This is the .htaccess file for the CakePHP Framework.
Please replace the index.php and ?url= to fit your needs.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
The "!-d" tells Apache to follow existing folders and "!-f" to follow existing files.
Everything else is channelled through index.php
As suggested in a comment, you have to be aware that if it's not working it could be because mod_rewrite is not enabled and you'll not get an error stating that fact, you'll probably only have a HTTP 404.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow