我一直在开发一个网站,但是我对子域的.htaccess似乎运行不正常。
我的子域中的.htaccess文件。
DirectoryIndex index.php
Options -MultiViews
RewriteEngine on
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+home\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ home.php?page=$1 [L,QSA]
当我进入子域时,可以找到index.php,但是当我进入home.php或/ home等时,它似乎不起作用,并重定向到我的404页(已在我的根目录中定义) 。
我的根目录.htaccess文件:
Options -MultiViews
RewriteEngine on
ErrorDocument 404 http://example.ca/error?id=404
ErrorDocument 403 http://example.ca/error?id=403
ErrorDocument 500 http://example.ca/error?id=500
RewriteCond %{http_host} ^www\.james-emerson\.ca [NC]
RewriteRule ^(.*)$ http://james-emerson.ca/$1 [R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^home$ index.php
我的根看起来像:
/
- content/
- include/
- sites/
- external/
- sbfg/ (subdomains subdirectory)
- content/
- include/
- .htaccess
- index.php
- home.php
- ...etc...
- .htaccess
- index.php
- ...etc...
如果可以的话,我将不胜感激。提前致谢。
在@anubhava的帮助下,我自己找出了解决问题的方法。
@anubhava给我的.htaccess文件:
DirectoryIndex index.php
Options -MultiViews
RewriteEngine on
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /sbfg//home\.php\?page=([^\s&]*)[&\s] [NC]
RewriteRule ^ /sbfg/%1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /sbfg/home.php?page=$1 [L,QSA]
不能正常工作,因为我的服务器要转到urlsites/external/sbfg/sbfg/home.php
而不是sites/home/sbfg/home.php
。直到我从根.htaccess文件中删除404文档代码,我才注意到错误。
然后我将代码更新为:
DirectoryIndex index.php
Options -MultiViews
RewriteEngine on
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /home\.php\?page=([^\s&]*)[&\s] [NC]
RewriteRule ^ /%1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /home.php?page=$1 [L,QSA]
然后将一些代码添加到我的根目录.htaccess文件中:
Options -MultiViews
ErrorDocument 404 http://james-emerson.ca/error?id=404
ErrorDocument 403 http://james-emerson.ca/error?id=403
ErrorDocument 500 http://james-emerson.ca/error?id=500
RewriteEngine on
RewriteCond %{http_host} ^www\.james-emerson\.ca [NC]
RewriteRule ^(.*)$ http://james-emerson.ca/$1 [R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^home$ index.php
# .htaccess file for the sbfg/home.php?page= code.
RewriteEngine on
RewriteCond %{THE_REQUEST} /home\.php\?page=([^\s&]*)[&\s] [NC]
RewriteRule ^ %1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ home.php?page=$1 [L,QSA]
现在它可以正常工作了。感谢大家对我的帮助,不知道为什么以前会遇到这些问题!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句