apache - 如何使用别名重写规则?

标签 apache url mod-rewrite rewrite alias

如果时间太长,我提前致歉。我认为更多的细节总比少的要好,希望我不会被吓到了:-)

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

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

可以将SEO友好且简短的URL的localhost/.../ih/sub/dir更改为localhost/.../index.php/sub/dir。 [我还没有在prod中继续这样做,但是我怀疑它也能正常工作。]但是,为了将它们结合在一起,我不得不将我的文档根目录从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 does not exist: C:/wamp/www/data,依此类推。

Sooooo ...我怎么能拥有一个超越别名的重写规则,而我的文档根目录不在我的计算机根目录下?

最佳答案

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

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

关于apache - 如何使用别名重写规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6533797/

相关文章:

python - 如何在您的服务器上运行 python 脚本?

PHP 不会在 Apache2 上解析 - CentOS 7

c++ - 从字符串中过滤掉 url

php - 当重写引擎删除 .php 和 .html 时,无法访问文件夹中的索引

java - 使用 Java 中的 POI 从 Excel 文件读取和写入值需要哪些 jar 文件?

c++ - FastCGI、Apache 和 C++

html - Windows 共享文件夹的 URL

css - 由于某种原因,css 文件中的所有 url 都被错误翻译

regex - 使用 htaccess 将 URL 的最后部分更改为大写?

php - 如何使用 htaccess 将带有参数的旧网址重定向到新的 seo 网址