duangai9678 2014-05-10 05:55
浏览 28

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

1st: I have http://pastebin.com/L7FVXjDU .htaccess file, now I want to add a new file /admin/index.php added this line to .htaccess: RewriteRule ^admin/([0-9]+)/?$ admin/index.php [L,QSA] but this redirect to home page.

2nd: in case of file not found 404 error, I want to redirect to notfound.html added this line: ErrorDocument 404 contents/notfound.html

but no success!

  • 写回答

1条回答 默认 最新

  • doumeng1897 2014-05-10 07:25
    关注

    Keep your .htaccess like this:

    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 *************************
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图