2013-01-23 89 views
8

好的,我得到了一個Apache本地主機服務器並運行了PHP和MySql。現在我想能夠使用.htaccess文件以及使用RewriteRule,但我不知道該放在哪裏。在apache本地主機服務器上使用.htaccess文件

我有以下目錄:

C:\dev\progs其中的Apache PHP和MySQL存儲,各自在自己的子目錄,即。 C:\dev\progs\Apache等等......

C:\dev\www其中存儲了所有站點文件。

我需要知道在哪裏放.htaccess文件,我需要做什麼配置,以及如果我是我的希望和夢想都沒有用。

感謝

+0

我以爲'.htaccess'配置不應該使用,如果你有權訪問服務器配置文件,在這種情況下,你這樣做。 – SeinopSys

+0

是的,我也聽到了一些關於它的信息,我只是覺得配置文件有點混亂。我還可以在'.htaccess'文件中找到更多的教程。 – KFox

回答

10

的.htaccess是一個應該被存儲在您的網頁是一個配置文件。總之,應該在c:\dev\www你的情況下,但你也應該讀this。順便說一句,不要忘記從線刪除哈希開啓mod_rewrite的它駐留

LoadModule rewrite_module modules/mod_rewrite.so 

,並通過改變

AllowOverride None 

AllowOverride All 
1

你把.htaccess啓用了.htaccess文件在您想要代碼控制的Web目錄中(以及任何子目錄)。對於重寫,它通常進入根目錄並作用於index.php頁面。

例如,如果你把.htaccess文件在\ dev的\ WWW \目錄下,你.htaccess文件具有類似RewriteRule ^(.*)$ /index.php?/$1 [L]這是說讓所有的字符的URL,並把它們添加到​​腳本正則表達式。 /$1是正則表達式中的反向引用。

12

在本地主機啓用的Apache服務器的.htaccess

1) Find your apache directly which uses the php installation . 
2) Open your httpd.conf with notepad, Which is located in the path \apache\conf directory 
3) Find the code like below  
     #LoadModule rewrite_module modules/mod_rewrite.so 
4) Remove # from above code 


# AllowOverride controls what directives may be placed in .htaccess files. 
# It can be "All", "None", or any combination of the keywords: 
# Options FileInfo AuthConfig Limit 
# 
AllowOverride All <--- make sure this is not set to "None" 


5) Save httpd.conf file 
6) Restart your apache server 
+1

更清晰的答案,謝謝! –

0

嘗試。

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /projectfolder/ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /projectfolder/index.php [L] 
</IfModule> 
相關問題