Php .htaccess mod rewrite目录索引
我想将index.php文件重新映射为目录 Im真正的url,它只是:Php .htaccess mod rewrite目录索引,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,我想将index.php文件重新映射为目录 Im真正的url,它只是:localhost/app/index.php?app=my-app 我是摩登写作新手,我知道它是如何工作的。我试着用这个: RewriteRule ^app/(.*)/?$ index.php?app=$1 [QSA] 而且它只适用于localhost/app/my-app。。现在,我如何使它在结尾处使用斜杠或不使用斜杠以及文件名index.php 我想要这样的东西: localhost/app/my-app local
localhost/app/index.php?app=my-app
我是摩登写作新手,我知道它是如何工作的。我试着用这个:
RewriteRule ^app/(.*)/?$ index.php?app=$1 [QSA]
而且它只适用于localhost/app/my-app
。。现在,我如何使它在结尾处使用斜杠或不使用斜杠以及文件名index.php
我想要这样的东西:
- localhost/app/my-app
- localhost/app/my-app/
- localhost/app/my app/index.php(如果是其他文件名,则为错误)
编辑:修复(请参阅评论)你的问题是什么?我更新了我的问题@Blueblazer172I,我刚刚在测试了这个
重写规则
,效果非常好。你想在这里达到什么目标?他想删除结尾处的尾随斜杠或将其留在那里谢谢!但是,如果用户输入了其他文件名而不是index.php ex:localhost/app/my-app/hello.php,该怎么办?我该如何将其重定向到错误页面?这一点很好。我修正了上面的答案。使用[^/]
而不是*?
,这将匹配/
到字符串末尾的所有内容,包括/hello.php
。
RewriteRule ^app/([^/]*)(?:|/|/index\.php)$ index.php?app=$1 [QSA]