如何使用别名重写规则?

发布于 2024-11-17 18:34:52 字数 1551 浏览 1 评论 0原文

如果这太长了,我提前道歉。我认为更多的细节比更少的细节更好,希望我没有胡言乱语:-)

我在我的笔记本电脑上使用 WAMP 进行本地开发,并且我有各种 c:/wamp/alias/* 文件每个都指向一个项目工作目录。我得到了一些出色的 mod_rewrite 帮助,并开始

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*\/)?ih(\/.*)?$ $1index.php$2 [L,QSA]

将 localhost/.../ih/sub/dir 更改为 localhost/.../index.php/sub/dir< /code> 用于 SEO 友好且简短的 URL。 [我还没有在产品中继续这样做,但我怀疑它也会同样有效。]但是,为了将它们放在一起,我必须从 c:/wamp/www/ 更改我的文档根目录 到 c:/,我真的不想这样做,以防万一我的 Apache 被黑客攻击,或者因为它是一个拼凑。

我的测试别名文件看起来像

Alias /testme "c:/var/tmp/wamp-testme/"
<Directory "c:/var/tmp/wamp-testme/">
  Options Indexes FollowSymLinks MultiViews
  AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*\/)?ih(\/.*)?$ $1index.php$2 [L,QSA]
</Directory>

,并且尝试加载 http://localhost/testme/rewrites/ih/sub/path 时出现的错误

[Thu Jun 30 06:46:13 2011] [error] [client 127.0.0.1]
  File does not exist: C:/wamp/www/var

匹配

Not Found
The requested URL /var/tmp/wamp-testme/rewrites/index.php/sub/path
  was not found on this server.

与浏览器中的 。果然,我的 c:/wamp/alias/flying.conf 文件中指向 c:/data/flying/ 目录的相同配置会抛出 File错误日志文件中不存在:C:/wamp/www/data,等等。

Sooooo...我怎样才能拥有超越别名的重写规则,而无需将我的文档根目录放在我的机器根目录中?

I apologize in advance if this is too long. I figure more detail is better than less and hope I'm not being horribly rambling :-)

I use WAMP on my laptop for local dev, and I have various c:/wamp/alias/* files each pointing to a project working directory. I've had some excellent mod_rewrite help and gotten

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*\/)?ih(\/.*)?$ $1index.php$2 [L,QSA]

to work to change localhost/.../ih/sub/dir to localhost/.../index.php/sub/dir for URLs that are both SEO-friendly and short. [I haven't gone on to do this in prod but I suspect it will work just as well.] However, to get it all together I had to change my doc root from c:/wamp/www/ to c:/, which I'd really rather not do just in case my Apache gets hacked and otherwise because it's a kludge.

My test alias file looks like

Alias /testme "c:/var/tmp/wamp-testme/"
<Directory "c:/var/tmp/wamp-testme/">
  Options Indexes FollowSymLinks MultiViews
  AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*\/)?ih(\/.*)?$ $1index.php$2 [L,QSA]
</Directory>

and the error I get when trying to load http://localhost/testme/rewrites/ih/sub/path is

[Thu Jun 30 06:46:13 2011] [error] [client 127.0.0.1]
  File does not exist: C:/wamp/www/var

with a matching

Not Found
The requested URL /var/tmp/wamp-testme/rewrites/index.php/sub/path
  was not found on this server.

in the browser. Sure enough, the same config in my c:/wamp/alias/flying.conf file that points to the c:/data/flying/ directory throws File does not exist: C:/wamp/www/data in the error log file, and so on.

Sooooo... How can I have a rewrite rule that transcends aliases without having my doc root at my machine root dir?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺ぐ爱和你が 2024-11-24 18:34:52

奇怪:尝试在重写规则中添加一个 PT 标志:这会强制将重写的 URL 发送回 URL 映射引擎。

编辑:尝试在目录上设置RewriteBase

Odd: try adding a PT flag to the rewrite rule: this forces the re-written URL to be sent back to the URL mapping engine.

EDIT: try setting the RewriteBase on the Directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文