Question

I have folder /aaa/. When users access to URL /aaa, my server should return contents of file /aaa/aaa.html. So I use following codes in /.htaccess to get the job done. It works.

DirectorySlash Off
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(aaa)$ /aaa/aaa.html [L]

I don't have folder /aaa/bbb/. When users access to URL /aaa/bbb, my server should return contents of file /aaa/bbb.html. I used following codes in /.htaccess to try to get the job done. But it doesn't work. It shows 404 page.

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(aaa\/bbb)$ /aaa/bbb.html [L]

I think the reason this code can't work is folder /aaa/bbb/ doesn't exist. I don't wanna create folder /aaa/bbb/. I wanna edit codes in /.htaccess to get job done. How should I change codes in /.htaccess to get the job done?

Thank you!

Was it helpful?

Solution

Your rules aren't correct actually. As RewriteCond %{REQUEST_FILENAME} -d means an existing directory and /aaa/bbb is not a directory.

Try this code:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(sub)/?$ /sub/try.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(sub/bbb)/?$ /sub/foo.php [L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top