在一些項(xiàng)目中牍鞠,URl 規(guī)則是怎么寫的咖摹?具體URL對(duì)應(yīng)個(gè)哪個(gè)PHP文件?那么就需要找項(xiàng)目的偽靜態(tài)文件了D咽觥S┣纭吐句!
最近訪問項(xiàng)目時(shí), 報(bào)錯(cuò) The requested URL /member/register was not found on this server.
發(fā)現(xiàn)是沒有開啟偽靜態(tài)的原因 于是乎店读,開始了配置偽靜態(tài)嗦枢。
1、查看Apache 配置文件是否開啟mod_rewrite模塊
文件路徑 apache/conf/httpd.conf
去掉 LoadModule Rewrite_module modules/mod_Rewrite.so 前面的'#' ; 如沒有請(qǐng)加上
2屯断、允許在任何目錄中使用“.htaccess”文件文虏,將“AllowOverride”改成“All”(默認(rèn)為“None”):
配置 httpd.conf 相關(guān)內(nèi)容, 將所有的 AllowOverride None 都改為 All
<Directory />
Options Indexes FollowSymLinks ExecCGI
AllowOverride All #默認(rèn) None
Order allow,deny
Allow from all
Require all granted
</Directory>
****重啟Apache**** 別忘記V逞荨Q趺亍!
3趴久、在項(xiàng)目更目錄配置 .htaccess 偽靜態(tài)文件
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteRule ^home$ /home/list.php [L]
RewriteRule index-([1-9]+[0-9]*).html$ index.php?p=$1
RewriteRule ^index\.html$ admin.php [L]
RewriteRule ^read\/([0-9]+)\.html$ read.php?id=$1 [QSA,L]
</IfModule>
注:
有時(shí)訪問項(xiàng)目URL丸相,還會(huì)報(bào)一下錯(cuò)誤
原因是 .htaccess 文件書寫有錯(cuò)誤, 排錯(cuò)時(shí)把下面的規(guī)則都注釋起來朋鞍,一條一條嘗試
最后大功告成已添!嘿嘿
喜歡的可以點(diǎn)點(diǎn)關(guān)注和喜歡~