【发布时间】:2017-02-06 04:22:58
【问题描述】:
所以我试图让一个 .htaccess 文件工作,它为我的 Web 服务重新映射一些 URL。我的 .htaccess 文件中有以下代码:
# General Settings
Options +FollowSymLinks -Indexes
Allow from all
AddCharset utf-8 .css .html .php
RewriteEngine on
RewriteBase /
# Option 1: Remove Index.php from URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
# Custom Options: Webservices
RewriteRule ^applications/([0-9]+)/infobox\.xml$ app/makeInfoBox/$1/ [L]
删除 index.php 工作正常,所以我认为 mod_rewrite 工作正常。但为什么我的 Web 服务规则不起作用?
它应该将https://example.com/applications/258/infobox.xml 重新映射到https://example.com/app/makeInfoBox/258/ 还是不应该?
当我添加 [R] 标志时,它确实有效,但我不想重定向 URL,我希望它重新映射。
感谢您的回答!
编辑: 因此,经过一些测试,我达到了我真的没有想法的地步。这是我的 mod_rewrite 代码:
# General Settings
AddCharset utf-8 .css .html .php
RewriteEngine on
RewriteBase /
# Custom Options: Webservices
RewriteRule ^applications/([0-9]+)/infobox\.xml$ app/makeInfoBox/$1/ [DPI]
# Option Remove Index.php from URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
我现在以高日志级别激活了日志记录。以下是记录的内容:
添加路径信息后缀:/etc/apache2/htdocs/webservices/applications -> /etc/apache2/htdocs/webservices/applications/258/infobox.xml
删除每个目录前缀:/etc/apache2/htdocs/webservices/applications/258/infobox.xml -> applications/258/infobox.xml
将模式 '^applications/([0-9]+)/infobox\.xml$' 应用到 uri 'applications/258/infobox.xml'
重写'applications/258/infobox.xml' -> 'app/makeInfoBox/258/'
添加每个目录前缀:app/makeInfoBox/258/ -> /etc/apache2/htdocs/webservices/app/makeInfoBox/258/
strip per-dir 前缀:/etc/apache2/htdocs/webservices/app/makeInfoBox/258/ -> app/makeInfoBox/258/
将模式 '^(.*)$' 应用到 uri 'app/makeInfoBox/258/'
RewriteCond: input='/etc/apache2/htdocs/webservices/app/makeInfoBox/258/' pattern='!-f' => 匹配
RewriteCond: input='/etc/apache2/htdocs/webservices/app/makeInfoBox/258/' pattern='!-d' => 匹配
重写'app/makeInfoBox/258/' -> '/index.php?/app/makeInfoBox/258/'
拆分uri=/index.php?/app/makeInfoBox/258/ -> uri=/index.php, args=/app/makeInfoBox/258/
尝试将前缀 /etc/apache2/htdocs/webservices/ 替换为 /
试图用上下文前缀替换上下文 docroot /etc/apache2/htdocs/webservices
使用 /index.php 进行内部重定向 [INTERNAL REDIRECT]
去除每个目录前缀:/etc/apache2/htdocs/webservices/index.php -> index.php
将模式 '^applications/([0-9]+)/infobox\.xml$' 应用于 uri 'index.php'
去除每个目录前缀:/etc/apache2/htdocs/webservices/index.php -> index.php
将模式 '^(.*)$' 应用于 uri 'index.php'
RewriteCond: input='/etc/apache2/htdocs/webservices/index.php' pattern='!-f' => 不匹配
通过/etc/apache2/htdocs/webservices/index.php
比较重定向和重新映射时的日志输出表明它几乎完全相同。
我做错了什么?
【问题讨论】:
标签: php apache .htaccess mod-rewrite