简体   繁体   English

mod_rewrite /$variable/file.php

[英]mod_rewrite /$variable/file.php

I've been trying to attempt this, but I am unable to yield any results. 我一直在尝试尝试此操作,但无法产生任何结果。 I'm trying to rewrite a variable into a "directory" in the url to multiple files.. I better explain this is what I mean. 我试图将变量重写为多个文件的url中的“目录”。.我更好地解释了这是我的意思。

Without the rewrite: 无需重写:

/index.php?var=test

/admin/panel.php?var=test

/faq.php?var=test

/directory/test.php?var=test

With the rewrite: 用重写:

/test/index.php

/test/admin/panel.php

/test/faq.php

/test/directory/test.php

I'd like to be able to pass other variables to the files as well.. example: 我也希望能够将其他变量传递到文件中。

/test/index.php?user=1&session=1233445

I realize that I could do a rewrite rule for every physical file and directory.. but I want it to be dynamic so if I add files to my site I don't have to keep editing the .htaccess file. 我意识到我可以为每个物理文件和目录执行重写规则。但是我希望它是动态的,因此,如果我将文件添加到站点,则不必继续编辑.htaccess文件。 Any help would be appreciated. 任何帮助,将不胜感激。 Thanks! 谢谢!

Try: 尝试:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(.*?/?)(index|panel|faq|test)\.php$ /$2$3.php?var=$1 [L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM