我在運行XAMPP的win8機器上。我有一個用.htaccess文件設置的虛擬主機目錄。我一直在研究如何重寫網址,並找到了RewriteEngine模塊。在我的httpd.conf文件的Apache,已經啓用的模塊:htaccess url-rewriting不能使用配置設置
LoadModule rewrite_module modules/mod_rewrite.so
好像下一步是更新我的.htaccess文件像這樣:
php_value register_globals off
DirectoryIndex default.php index.php
ErrorDocument 404 /filenotfound.html
RewriteEngine On
RewriteBase/
RewriteRule ^Home$ Default.php [L]
RewriteRule ^AboutMe$ About.php [L]
RewriteRule ^Work$ Work.php [L]
RewriteRule ^Blog//Categories$ Blog/Categories.php [L]
RewriteRule ^Blog//([^/.]+)/?$ Blog/Posts.php?val=$1 [L]
我按照一對夫婦SO問題(config和rewriting w/ params),但無法使最簡單的重寫工作。我幾次重新啓動apache而沒有任何結果。
雖然我在這裏,這是歸結爲相關的一切:我的文件夾結構:
root
.htaccess
Blog
AuthorPanel.php
Categories.php
Post.php
Posts.php
Default.php
About.php
Work.php
這些都是我期待實現(我已經嘗試過大多數)的重寫:
site.com/Default.php => site.com/Home
site.com/About.php => site.com/AboutMe
site.com/Blog/Categories.php => site.com/Blog/Categories
site.com/Blog/Posts.php?id=3&val=Android => site.com/Blog/Android
site.com//Blog/Post.php?id=4&title=Working+with+ActionBar => site.com/Blog/Working-with-ActionBar
更新1在的httpd-vhosts.conf我甚至使用RewriteEngine敘述上和重寫規則試過,沒有運氣之一:
<VirtualHost *>
DocumentRoot "C:/Users/ben/Documents/PHP/benWIT"
ServerName benWIT.local
<Directory "C:/Users/ben/Documents/PHP/benWIT">
RewriteEngine on
Order allow,deny
AllowOverride all
Allow from all
Require all granted
RewriteRule ^Home$ Default.php [L]
RewriteRule ^AboutMe$ About.php [L]
RewriteRule ^Work$ Work.php [L]
</Directory>
</VirtualHost>
我將使用一個共享的託管環境,所以我不知道如果我將有機會獲得任何Apache的配置文件。現在我有一個虛擬主機設置在虛擬主機,並在我的httpd.conf我有 將AllowOverride全部。我沒有在Alias鏈接中看到我設置了這些別名。感謝您的幫助 –
benbob
,您可以將別名鏈接放在htaccess文件中。由於您使用的是共享主機,因此無法解決問題,因此您必須使用htaccess。只要確保加載了mod_alias即可。 – Rijndael
將任何別名規則添加到.htaccess文件時,我也會收到服務器錯誤「500」。 LoadModule mod_alias.so也加載到httpd.conf中。我也嘗試在vhost和httpd文件中刪除RewriteEngine。 – benbob