gpt4 book ai didi

.htaccess - 别名和 mod_rewrite

转载 作者:行者123 更新时间:2023-12-04 15:01:10 25 4
gpt4 key购买 nike

我试图让 Symfony1.4 和 Symfony2 在 Apache(2.2.22)中的同一主机上工作 - 我认为问题在于两者都使用 mod_rewrite 将请求定向到 php Controller /脚本。这是我的配置

httpd.conf

# Symfony 1.4
<VirtualHost *:80>
DocumentRoot "d:/wamp/www/wlnew/web"
DirectoryIndex index.php
<Directory "d:/wamp/www/wlnew/web">
AllowOverride All
Allow from All
</Directory>

Alias /sf d:/wamp/www/wlnew/lib/vendor/symfony/data/web/sf
<Directory "d:/wamp/www/wlnew/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
# Symfony 2
Alias /another "d:/wamp/www/another/web/"
<Directory "d:/wamp/www/another/web">
Options Indexes FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

然后每个版本的 Symfony 都有一个 .htaccess用于重写请求

Symfony 1 .htaccess
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f

# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

Symfony 2 .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>

我希望能够使用 localhost/重定向到 Symfony 1 前端 Controller index.php但是当我使用 localhost/another所有请求都应该转发到 symfony2 前端 Controller app.php但它们不是——它们被转发到 symfony1 前端 Controller ( index.php)。如果我为 Symfony2 使用 Controller 的文件名,它可以工作,即 localhost/another/app.php
当我使用 /another 时,如何让 apache 将请求转发到 Symfony2 Controller 别名?

更新

我启用了重写日志记录......这就是我得到的:
[perdir D:/wamp/www/another/web/] strip per-dir prefix: D:/wamp/www/another/web/ -> 
[perdir D:/wamp/www/another/web/] applying pattern '^(.*)$' to uri ''
[perdir D:/wamp/www/another/web/] RewriteCond: input='D:/wamp/www/another/web/' pattern='!-f' => matched
[perdir D:/wamp/www/another/web/] rewrite '' -> 'app.php'
[perdir D:/wamp/www/another/web/] add per-dir prefix: app.php -> D:/wamp/www/another/web/app.php
[perdir D:/wamp/www/another/web/] internal redirect with D:/wamp/www/another/web/app.php [INTERNAL REDIRECT]
[perdir D:/wamp/www/wlnew/web/] add path info postfix: D:/wamp/www/wlnew/web/wamp -> D:/wamp/www/wlnew/web/wamp/www/another/web/app.php
[perdir D:/wamp/www/wlnew/web/] strip per-dir prefix: D:/wamp/www/wlnew/web/wamp/www/another/web/app.php -> wamp/www/another/web/app.php
[perdir D:/wamp/www/wlnew/web/] applying pattern '^$' to uri 'wamp/www/another/web/app.php'
[perdir D:/wamp/www/wlnew/web/] add path info postfix: D:/wamp/www/wlnew/web/wamp -> D:/wamp/www/wlnew/web/wamp/www/another/web/app.php
[perdir D:/wamp/www/wlnew/web/] strip per-dir prefix: D:/wamp/www/wlnew/web/wamp/www/another/web/app.php -> wamp/www/another/web/app.php
[perdir D:/wamp/www/wlnew/web/] applying pattern '^([^.]+)$' to uri 'wamp/www/another/web/app.php'
[perdir D:/wamp/www/wlnew/web/] add path info postfix: D:/wamp/www/wlnew/web/wamp -> D:/wamp/www/wlnew/web/wamp/www/another/web/app.php
[perdir D:/wamp/www/wlnew/web/] strip per-dir prefix: D:/wamp/www/wlnew/web/wamp/www/another/web/app.php -> wamp/www/another/web/app.php
[perdir D:/wamp/www/wlnew/web/] applying pattern '^(.*)$' to uri 'wamp/www/another/web/app.php'
[perdir D:/wamp/www/wlnew/web/] RewriteCond: input='D:/wamp/www/wlnew/web/wamp' pattern='!-f' => matched
[perdir D:/wamp/www/wlnew/web/] rewrite 'wamp/www/another/web/app.php' -> 'index.php'
[perdir D:/wamp/www/wlnew/web/] add per-dir prefix: index.php -> D:/wamp/www/wlnew/web/index.php
[perdir D:/wamp/www/wlnew/web/] strip document_root prefix: D:/wamp/www/wlnew/web/index.php -> /index.php
[perdir D:/wamp/www/wlnew/web/] internal redirect with /index.php [INTERNAL REDIRECT]
[perdir D:/wamp/www/wlnew/web/] strip per-dir prefix: D:/wamp/www/wlnew/web/index.php -> index.php
[perdir D:/wamp/www/wlnew/web/] applying pattern '^$' to uri 'index.php'
[perdir D:/wamp/www/wlnew/web/] strip per-dir prefix: D:/wamp/www/wlnew/web/index.php -> index.php
[perdir D:/wamp/www/wlnew/web/] applying pattern '^([^.]+)$' to uri 'index.php'
[perdir D:/wamp/www/wlnew/web/] strip per-dir prefix: D:/wamp/www/wlnew/web/index.php -> index.php
[perdir D:/wamp/www/wlnew/web/] applying pattern '^(.*)$' to uri 'index.php'
[perdir D:/wamp/www/wlnew/web/] RewriteCond: input='D:/wamp/www/wlnew/web/index.php' pattern='!-f' => not-matched
[perdir D:/wamp/www/wlnew/web/] pass through D:/wamp/www/wlnew/web/index.php

似乎 .htaccess正在读取 Symfony2 ( /another ) 并重定向到 app.php但随后读取另一个 .htaccess然后重定向到 index.php ...我怎样才能让重写停止在 app.php

最佳答案

看来配置需要RewriteBase需要为 .htaccess 设置。

RewriteBase /another

这应该有效。 This link helped in this answer.

另外, here are some notes through our discussion on chat关于其他设置如何影响以及如何 RewriteCond可以纠正无限的内部重定向循环。可能会帮助其他人。总的来说,mod_rewrite 是一个困难的模块。

关于.htaccess - 别名和 mod_rewrite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14463729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com