Php htaccess url重写虚拟目录
我想使用2个虚拟(非真实目录路径)创建漂亮的URL(斜线参数) 出于某种原因,当我包含虚拟路径时,重写规则不会捕获请求的URL 当前代码不工作:(未发生重写) 但是,如果没有任何虚拟路径,它可以工作:Php htaccess url重写虚拟目录,php,.htaccess,mod-rewrite,url-rewriting,Php,.htaccess,Mod Rewrite,Url Rewriting,我想使用2个虚拟(非真实目录路径)创建漂亮的URL(斜线参数) 出于某种原因,当我包含虚拟路径时,重写规则不会捕获请求的URL 当前代码不工作:(未发生重写) 但是,如果没有任何虚拟路径,它可以工作: RewriteRule ^file/(.*)$ realpath1/file.php?param=$1 如何在htaccess文件中使用两个虚拟路径 最终输出应为: mysite.com/virtualpathone/file/param/100 及 在DocumentRoot中尝试此.hta
RewriteRule ^file/(.*)$ realpath1/file.php?param=$1
如何在htaccess文件中使用两个虚拟路径
最终输出应为:
mysite.com/virtualpathone/file/param/100
及
在DocumentRoot中尝试此.htaccess:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^virtualpathONE/file/(.*)$ realpath1/file.php?param=$1 [L,NC,QSA]
RewriteRule ^virtualpathTWO/file/(.*)$ realpath2/file.php?param=$1 [L,NC,QSA]
什么不起作用?使用虚拟路径时使用了什么URL?出现了什么错误?谢谢您的评论。没有错误。只加载一个普通页面,而不重写url。我使用了site.com/virtualpathone/file/param/100,只是尝试了一下。Url不会改变。如果我手动在地址栏中键入漂亮的url,如:site.com/virutalpathone/file/param/100,我会得到一个找不到的页面错误。请尝试使用此准确的url
site.com/virutalpathone/file/100
。您在htaccess中有更多的规则吗?如果http://domain.com/virutalpathONE/file/100
给出404,然后也尝试:http://domain.com/realpath1/file.php?param=100
还要确保.htaccess位于根目录中,即比/realpath1/
mysite.com/virtualpathtwo/file/param/100
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^virtualpathONE/file/(.*)$ realpath1/file.php?param=$1 [L,NC,QSA]
RewriteRule ^virtualpathTWO/file/(.*)$ realpath2/file.php?param=$1 [L,NC,QSA]