![](/img/trans.png)
[英]htaccess rewriterule windows/linux , domain to subpage
[英]RewriteRule not writing at all in .htaccess for Windows (Apache)
問題
我正在使用教程來學習使用Zend Framework。 我無法超越“確保.htaccess正常工作”部分。 我了解Windows對此有很多問題,我將提及自己所做的事情,以便我們可以在同一頁面上。
.htaccess的內容如下:
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [NC,L]
簡而言之,當我鍵入url \\ fileDoesntExist時,.htaccess規則應捕獲並將其轉換為index.php。 就這樣。
這就是問題,它根本不是重寫請求,給我一個404 not found錯誤,據我所知,因為它正在尋找“ fileDoesntExist”(顯然不存在)。 當我查看該虛擬主機的錯誤日志時,Get帖子是GET / fileDoesntExist ...這是錯誤的,因為由於.htaccess中放置了RewriteRule,因此它應該是GET /index.php。
環境
Windows 8 Apache 2.4
httpd.conf文件
LoadModule rewrite_module modules/mod_rewrite.so --> UNCOMMENTED
AccessFilename htaccess --> (some have said that for Windows, it should be placed without the
leading dot)
<Directory "C:\Apache24\hosts\zf2-tutorial\public">
DirectoryIndex index.php
AllowOverride all
Order Deny,Allow
Allow from all
Options Indexes FollowSymLinks
Require all granted
RewriteRule ^(.*)$ index.php [NC,L] --> one user said that in windows if the rewriteRule is
not placed here, then it won´t take place.
</Directory>
想法無濟於事
通過phpinfo(); 我可以看到rewrite_module實際上已經加載。 如果我刪除.htaccess中的內容並放入類似“aksdhfñashfña”(垃圾)的內容,則會收到“內部服務器錯誤”。
我不知道這可能是什么問題,將不勝感激,因為花費大量時間進行配置而不是進行開發非常令人沮喪。
遵循De Morgan的法律,我嘗試調整.htaccess的內容,以便它僅在找不到所請求的頁面時才起作用。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
Rewritecond %{REQUEST_FILENAME} !-d
Rewritecond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [NC,L]
AccessFilename
指令(默認使用.htaccess
) 將您的<Directory>
更改為(消除所有混亂)
<Directory "C:/Apache24/hosts/zf2-tutorial/public"> <!-- forward slashes --> Options Indexes FollowSymLinks AllowOverride All Order allow,deny <!-- Fix your order (allow first) --> Allow from all </Directory>
確保.htaccess
位於DocumentRoot
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.