我正在编写一个通过Oracle数据库动态填充的网站。
我已经完成了桌面网站,现在需要创建一个移动网站。由于网站计划的外观不同,我选择为移动和桌面网站创建 2 个不同的"模板",例如网站。
但是,对于我的桌面网站,一切都是在index.php文件的基础上构建的,以便允许它是完全动态的。因此,页面看起来像 url 中的www.domain.com/index.php/page
。
对于桌面站点,这有效。我正在使用通用索引.php删除重写规则,以便使网址www.domain.com/page
仍然显示与上一个URL相同的页面。
我的问题是,现在我有www.domain.com/mobile/index.php
.它已经创建并且大部分一直在工作,但是在尝试向移动网站添加其他动态页面时。 例如,www.domain.com/mobile/index.php/about
只是重定向到www.domain.com/mobile/
,它甚至不包括URL的about
部分。
经过大量调试,我发现绝对是导致问题.htaccess
。
如果您对我的问题有任何见解,请帮助我。
提前致谢
编辑 1
重写规则如下
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index'.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index'.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
您可以在/mobile/.htaccess
文件中使用以下代码:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /mobile/
RewriteCond %{THE_REQUEST} /index'.php [NC]
RewriteRule ^index'.php(?:/(.*))?$ $1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [L]
这将覆盖父 .htaccess 中存在的所有规则/mobile/
URI 路径。
简化版本使其在根 .htaccess 中工作:
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(mobile)/(.*)$ $1/index.php/$2 [L,NC]
# Directs all EE web requests through the site index file
RewriteRule ^(.*)$ /index.php/$1 [L]
根据您提到的调试,您的 .htaccess 中有一条规则,该规则正在将www.domain.com/mobile/index.php/about
重写为 www.domain.com/mobile/
。因此,如果您找到这是哪条规则,您可以在其上方添加一个规则,该规则将捕获移动页面的请求 URL,然后不允许运行有问题的以下规则。像这样:
RewriteRule ^mobile/index.php/([a-zA-Z0-9-_]+)$ ^mobile/index.php/$1 [L,QSA]
L
可确保如果用户的请求与此规则匹配,则不会执行其他规则(包括导致问题的规则)。
谢谢你们俩给出的答案,但是它们都没有奏效,我现在已经解决了这个问题,这与最后的最终重写规则有关
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
我需要将其更改为
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/mobile/.* [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /mobile/.* [NC]
RewriteRule ^(.*)$ mobile/index.php/$1 [L]
这样它就可以与移动和桌面网站一起使用。