.htaccess在向网站添加新页面时重定向到索引页面

时间:2014-05-10 05:55:09

标签: php apache .htaccess

第一:我有http://pastebin.com/L7FVXjDU .htaccess文件,现在我想添加一个新文件/admin/index.php将此行添加到.htaccess:RewriteRule ^admin/([0-9]+)/?$ admin/index.php [L,QSA]但是这个重定向到主页。 / p>

第二:如果找不到文件404错误,我想重定向到notfound.html添加以下行:ErrorDocument 404 contents/notfound.html

但没有成功!

1 个答案:

答案 0 :(得分:0)

保持你的.htaccess像这样:

DirectoryIndex index.html index.php  index.htm index.cgi    
ErrorDocument 404 contents/notfound.html

RewriteEngine on
RewriteBase /

#index.php to host
RewriteCond %{THE_REQUEST} ^.*/index\.php 
RewriteRule ^(.*)index.php$ /$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

#admin home
RewriteRule ^admin/([0-9]+)/?$ admin/index.php [L,QSA]

#pagination rewriting
RewriteRule ^(.*?)/([0-9]+)/([0-9]+)?$ index.php?page=$2&c_id=$3 [L,QSA]

#business review rewriting
RewriteRule ^([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([0-9]+)/([a-zA-Z0-9-_]+)/?$ contents/details.php?b_id=$4&status=$5 [L,QSA]

#business rewriting
RewriteRule ^([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([0-9]+)/?$ contents/details.php?b_id=$4 [L,QSA]

#claim page rewriting
RewriteRule ^claim/([0-9]+)/?$ contents/claim.php?b_id=$1 [L,QSA]

#report page rewriting
RewriteRule ^report/([0-9]+)/?$ contents/report.php?b_id=$1 [L,QSA]

#rewrite host to index.php
RewriteCond %{THE_REQUEST} ^(.*?)$
RewriteRule ^/?$ index.php [L]

#main pages rewriting
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php !-f    
RewriteRule ^(.*?)/?$ contents/$1.php [L]

#category rewriting
<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} -f [OR]
   RewriteCond %{REQUEST_FILENAME} -d
   RewriteRule ^ - [L]
   RewriteRule ^([_0-9a-zA-Z-]+/)?$ [L]
   RewriteRule . index.php [L]
 </IfModule>

 # ******************* admin *************************