这就是我需要发生的事情:
我在使用web.config进行ISS安装时工作正常,但我无法将其转换为.htaccess。这是我到目前为止所做的:
<IfModule mod_rewrite.c>
RewriteEngine On
#Alternate default index page
DirectoryIndex index.php?page=home
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) index.php?page=$1 [QSA,L]
RewriteRule "^/index\.php$" "/index.php?page=home" [PT]
RewriteRule ^/?([^/d]+)/?$ index.php?page=$1 [L,QSA]
AddCharset UTF-8 .php
ErrorDocument 404 /404.php
</IfModule>
使用上面的htaccess代码,3)很好,但其他两个不起作用。
任何人都可以帮助这个菜鸟吗?我在Godaddy主持,如果这有所作为。此外,此站点位于测试子子目录的深处,因此任何根指示都不起作用。
更新:
我可以通过将完整的URL添加到RewriteRule来获得SOMETHING -
AddCharset UTF-8 .php
RewriteEngine On
#Alternate default index page
RewriteRule ^home/?$ http://example.com/test/site/index.php?page=home [L,QSA,NC]
RewriteRule ^/?$ http://example.com/test/site/home [L,QSA,NC]
# add .php extension if corresponding file exists
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1 [L]
# everything else
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) http://example.com/test/site/index.php?page=$1 [QSA,L]
但现在它与我想要的相反;而不是去“example.com/test/site/about”,它重写它去“example.com/test/site/index.php?page=about”
更新2:
最终工作版本以防其他人遇到同样的问题:
AddCharset UTF-8 .php
RewriteEngine On
RewriteBase /test/site/
#Alternate default index page
RewriteRule ^home/?$ index.php?page=home [L,QSA,NC]
RewriteRule ^/?$ /home [L,QSA,NC]
DirectoryIndex index.php?page=home
# everything else
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) index.php?page=$1 [QSA,L]
答案 0 :(得分:1)
这样做:
AddCharset UTF-8 .php
RewriteEngine On
#Alternate default index page
RewriteRule ^home/?$ index.php?page=home [L,QSA,NC]
# add .php extension if corresponding file exists
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
# everything else
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) index.php?page=$1 [QSA,L]
不需要 ErrorDocument
,因为每个非文件,非dir都会转到index.php?page=...