A. 設置godaddy 關於.htaccess 文件的設置 我想把網站首頁打開優先順序設置為 index.php 請問怎麼操作
DirectoryIndex index.php
這樣
B. 如何利用.htaccess文件對PHP網站或文件進行偽靜態處理
利用.htaccess文件對PHP網站進行偽靜態處理要考慮兩點:
一.伺服器支持偽靜態,比如Apache要開啟mod_rewrite模塊支持
二.利用.htaccess完成偽靜態需要根據不同的網站系統進行不同的設置,以下是一些常見系統的.htaccess設定:
01.wordpress:
# BEGIN WordPress
<IfMole mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfMole>
02.Phpwind
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
RewriteRule ^(.*)simple/([a-z0-9\_]+\.html)$ $1/simple/index.php?$2
03.Discuz
RewriteEngine On
# Rewrite 系統規則請勿修改
RewriteRule ^archiver/((fid|tid)-[0-9]+\.html)$ archiver/index.php?$1
RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ viewthread.php?tid=$1&extra=page\%3D$3&page=$2
RewriteRule ^space-(username|uid)-(.+)\.html$ space.php?$1=$2
RewriteRule ^tag-(.+)\.html$ tag.php?name=$1
04.ecshop
RewriteEngine On
# direct one-word access
RewriteRule ^index\.html$ index\.php [L]
RewriteRule ^category$ index\.php [L]
# access any object by its numeric identifier
RewriteRule ^feed-c([0-9]+)\.xml$ feed\.php\?cat=$1 [L]
RewriteRule ^feed-b([0-9]+)\.xml$ feed\.php\?brand=$1 [L]
RewriteRule ^feed\.xml$ feed\.php [L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ category\.php\?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html$ category\.php\?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ category\.php\?id=$1&brand=$2&page=$3&sort=$4&order=$5 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$ category\.php\?id=$1&brand=$2&page=$3 [QSA,L]
RewriteRule ^category-([0-9]+)-b([0-9]+)(.*)\.html$ category\.php\?id=$1&brand=$2 [QSA,L]
RewriteRule ^category-([0-9]+)(.*)\.html$ category\.php\?id=$1 [QSA,L]
RewriteRule ^goods-([0-9]+)(.*)\.html$ goods\.php\?id=$1 [QSA,L]
RewriteRule ^article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ article_cat\.php\?id=$1&page=$2&sort=$3&order=$4 [QSA,L]
RewriteRule ^article_cat-([0-9]+)-([0-9]+)(.*)\.html$ article_cat\.php\?id=$1&page=$2 [QSA,L]
RewriteRule ^article_cat-([0-9]+)(.*)\.html$ article_cat\.php\?id=$1 [QSA,L]
RewriteRule ^article-([0-9]+)(.*)\.html$ article\.php\?id=$1 [QSA,L]
RewriteRule ^brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html brand\.php\?id=$1&cat=$2&page=$3&sort=$4&order=$5 [QSA,L]
RewriteRule ^brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html brand\.php\?id=$1&cat=$2&page=$3 [QSA,L]
RewriteRule ^brand-([0-9]+)-c([0-9]+)(.*)\.html brand\.php\?id=$1&cat=$2 [QSA,L]
RewriteRule ^brand-([0-9]+)(.*)\.html brand\.php\?id=$1 [QSA,L]
RewriteRule ^tag-(.*)\.html search\.php\?keywords=$1 [QSA,L]
RewriteRule ^snatch-([0-9]+)\.html$ snatch\.php\?id=$1 [QSA,L]
RewriteRule ^group_buy-([0-9]+)\.html$ group_buy\.php\?act=view&id=$1 [QSA,L]
RewriteRule ^auction-([0-9]+)\.html$ auction\.php\?act=view&id=$1 [QSA,L]
05.phpcms
RewriteEngine On
RewriteRule ^(.*)content-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/index\.php\?m=content&c=index&a=show&catid=$2&id=
$3&page=$4
RewriteRule ^(.*)show-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/index\.php\?m=content&c=index&a=show&catid=$2&id=
$3&page=$4
RewriteRule ^(.*)list-([0-9]+)-([0-9]+).html$ $1/index\.php\?m=content&c=index&a=lists&catid=$2&page=$3
C. 加了.htaccess文件為什麼仍不能去掉index.php
1. 在httpd.conf中,將 所有 AllowOverride None 改為 AllowOverride All 好像共有三處吧,然後重啟apache2. 在.htaccess文件中,是這樣的配置:RewriteEngine onRewriteCond $1 !^(index\.php|robots|stafile|upload|\.txt)RewriteRule ^(.*)$ /index.php/$1 [L]如果你是直接在根目錄配置的,則以上就可以了;假如你的項目在根目錄底下一層,則 RewriteRule ^(.*)$ /index.php/$1 [L] 得變為 RewriteRule ^(.*)$ /項目文件夾名/index.php/$1 [L]以上兩步已經可以去掉 index.php了,假如項目中的路徑,為了去掉index.php,還需要第 3 步 操作,因為第 3 步 是影響到 site_url();這個函數的。3. 將 config.php中的 $config['index_page'] = 'index.php'; 改為 $config['index_page'] = '';
D. 如何利用.htaccess文件對PHP網站或文件進行偽靜態處理
一、檢查伺服器是否支持偽靜態處理:
必須要空間支持 Rewrite 以及對站點目錄中有 .htaccess
的文件解析,才有效.找到apache安裝目錄下的httpd.cof文件,去掉LoadMole rewrite_mole
moles/mod_rewrite.so前面的#(大概在154行,我的默認是開啟)
二、在httpd.cof中查找以下部分:
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
改為:
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
如果沒有,手動添加。(PS:LZ試過,在最近的新版本的Apache上即使沒有這個,.htaccess照樣生效。但是不同伺服器及版本的原因,建議加上)
三、重啟apache伺服器,添加.htaccess文件
建立.htaccess文件的方式:
1、保存文件的時候將文檔保存成名為「***.txt」,再將其上傳到伺服器上,之後直接使用FTP軟體來重命名為「.htaccess」。(適合windows)
2、保存文件的時候選擇文件—>另存為,保存類型選所有文件,然後文件名輸入.htaccess 。(適合windows)
3、直接在你的Unix或Linux虛擬主機上建立。
4、先用記事本編寫好,隨便保存為一個什麼文件名,然後打開「命令提示符」(CMD),然後再用重命名命令(rename),例如:rename c:\htaccess.txt .htaccess
請注意: .htaccess必須,保存為ANSI 格式,以ASCII模式上傳,最好將其許可權設置為644。
一般我們將.htaccess文件放置在網站的根目錄,控制所在目錄及所有子目錄,當然也可以放在網站的任何一個子目錄下,但如果放置在子目錄中,子目錄中的指令會覆蓋更高級目錄或者主伺服器配置文件中的指令。
在博客收錄集(http://www.ido321.com/1112.html)為例,本地.htaccess文件如下:
#rewriteengine為重寫引擎開關on為開啟off為關閉
RewriteEngine On
RewriteRule ^index\.html$ index.php
RewriteRule ^webmore\.html$ webmore.php
以index.html代替index.php webmore.html代替webmore.php。
.htaccess支持正則表達式,例如:
原始 news/detail.php?id=2 偽靜態 news/detail_2.html
RewriteRule ^news/detail_([0-9]{1,})\.html$ news/detail.php?id=$1
E. index.php和.htaccess是根目錄的文件么我給刪了,怎麼辦
htaccess文件刪了,可以重新創建個上傳就行了,index.php是你程序的首頁嗎?這個刪了你網上還能正常訪問嗎
F. thinkPHP無法隱藏index.php,設置了htaccess和Apache
thinkphp取消index.php的話需要兩方面改動,一是apache開啟rewrite模塊或iis安裝rewrite組件;另一方面是在網站下放入重寫規則文件,apache對應.htaccess,iis對應httpd.ini
G. htaccess如何自定義php後綴
首先,apache配置下,有一個配置表示默認將後綴為.php的文件進行解析,當然你可以進行配置,改成其它後綴的。不過你既然有.htaccess文件了,為什麼要加那個後綴呢?一般裡面的規則如下
<IfMole mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfMole>
定義好這個規則後就不用加text.php了。只不過,apache一般默認解析的是index.php,所以我提供的規則也是默認指向index.php的。
H. ThinkPHP實現偽靜態如何去掉目錄中的index.php
Myapp是我的項目文件名,默認的訪問地址是上面這樣的。為了使URL更加簡介友好,現在要去掉中間的index.php,方法如下:
1。確認httpd.conf配置文件中載入了mod_rewrite.so 模塊,載入的方法是去掉mod_rewrite.so前面的注釋#號
2。講httpd.conf中的Allowoverride None 將None改為All
3。打開對應的項目配置文件,我的項目配置文件是Myapp/Conf/config.php ,在這個配置文件數組中增加一行,『URL_MODEL』=>2
4。在項目的根目錄下面建立一個.htaccess文件,裡面寫入下面的內容:
<IfMole rewrite_mole>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfMole>
如果你的伺服器支持rewrite,現在就可以通過http://localhost/Myapp/Index/index/訪問Index模塊下面的index操作。
I. index.php怎麼解決
因為你後台沒有設置默認主頁文件第一個為index.php
去控制面板設置下順序就可以了。
J. url重寫,在.htaccess里怎麼把index.php改掉
RewriteEngine On
RewriteBase /
RewriteRule ^localhost/abc@123.com$ localhost/index.php?em=abc@123.com