Rewriting is working using this htaccess file, but for some reason this new rule I created doesn't seem to be working. Here is the new rule:
RewriteRule ^(.*)/(webapps|gamedev|digitalart)$ $1/index.php [NC,PT,L]
Here is my entire set of rewrite rules:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^(.*)/(webapps|gamedev|digitalart)$ $1/index.php [NC,PT,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.] )$ $1.php [L]
The public URL that this .htaccess is contained in is here:
https://dustinhendricks.com/test
The url I am testing is here:
https://dustinhendricks.com/test/gamedev
I expect the above URL to navigate (without changing the URL in browser) to here:
https://dustinhendricks.com/test/index.php
Instead it is returning a 404 error. Any ideas as to why this rewrite isn't working as expected? Tested it here, but seems to rewrite fine in this site htaccess tester
CodePudding user response:
Have your .htaccess this way:
RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# add .php if there is a matching .php file
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(. ?)/?$ $1.php [L]
# rewrite these paths to index.php
RewriteRule ^(webapps|gamedev|digitalart)/?$ index.php [NC,L]
Note that your .htaccess is already inside test/
subdirectory, hence matched pattern in RewriteRule
will be relative to test/
subdirectory.