.htaccess RewriteRule not working in subdirectory

情到浓时终转凉″ 提交于 2019-11-28 11:05:27

I had to e-mail my server's administrator for help and it turns out that .htaccess treats its own path as root; I simply removed the first / before the ^ in each rule. My final .htaccess file looks like this:

RewriteEngine On

RewriteRule ^welcome/$ index.php?action=welcome [L,QSA]
RewriteRule ^page/(.*)/$ index.php?action=page&url=$1 [L,QSA]
RewriteRule ^post/(.*)/$ index.php?action=post&url=$1 [L,QSA]

The ^ means the start of the string. The RewriteRules will look at everything after example.com/ so you need to include storage/new/ in your pattern (or remove the ^).

Also I'd probably want to add the NC flag so your pattern is matched without regards to case sensitivity (e.g. /Page/ or /page/ will both work). Which means you can change the [a-zA-Z0-9] pattern to just [a-z0-9]

RewriteRule ^storage/new/welcome/$ index.php?action=welcome [L,NC]
RewriteRule ^storage/new/page/([a-z0-9]+)/$ index.php?action=page&url=$1 [L,NC]
RewriteRule ^storage/new/post/([a-z0-9]+)/$ index.php?action=post&url=$1 [L,NC]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!