简体   繁体   English

mod_rewrite在子目录中而不在基本目录中工作

[英]mod_rewrite works in subdirectory not in base directory

The rewrite rule is: 重写规则为:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_\-.]+)/?$ storefront.php?id_user=$1 [L]

When placed in a subdirectory ie: http://example.com/subdirectory/ it works on redirecting a url from http://example.com/subdirectory/user to http://example.com/subdirectory/storefront.php?id_user=user . 当放置在子目录中时,即: http://example.com/subdirectory/ : http://example.com/subdirectory/它可以将URL从http://example.com/subdirectory/user重定向到http://example.com/subdirectory/storefront.php?id_user=user

When place in base directory ie: http://example.com/ it fails to redirect the url http://example.com/user to http://example.com/storefront.php?id_user=user 当放置在基本目录(即http://example.com/它无法将URL http://example.com/user重定向到http://example.com/storefront.php?id_user=user

What am I doing wrong? 我究竟做错了什么?

okay i am getting the effect i want by using this rewrite rule which if feel is a hack and not the way it really should be. 好吧,我通过使用此重写规则来获得想要的效果,如果感觉是hack,而不是它应该是的样子。 then again..it works so going with it unless someone enlightens me on what is happening. 然后再..它起作用,除非有人启发我发生了什么,否则它会继续工作。

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_\-.]+)/?$ http://example.com/subdirectory/storefront.php?=id_user=$1 [L]

basically i rewrote it to the directory that was working. 基本上我将其重写到正在工作的目录中。 but ultimately this is not what i want since i want to migrate subdirectory to be base directory down the road and this issue is preventing that. 但是最终这不是我想要的,因为我想将子目录迁移为基础目录,而这个问题阻止了这种情况。

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

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