simple redirect to default page with htaccess
-
05-10-2019 - |
Question
The htaccess file requires an entry at the end of /folder/
to redirect the page
example:
http://www.server.com/folder/"some-page-name"
If no page is defined as, then I want it to be "index" by default
the htacess
RewriteBase /folder/
RewriteRule ^(.*)$ subfolder/index.php/?page=$1 [L]
Solution
# there must be something after /folder/ for this to work
RewriteBase ^/folder/(.+)$ /folder/subfolder/index.php/?page=$1 [L]
# if there isn't, do a catch-all redirect (change to whatever "index by default" means)
RewriteRule ^/folder/$ /folder/index
OTHER TIPS
If you want to check whether the file exists or not and redirect the users to the index (if is does not), use the following condition:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond .* index [R=301]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow