本文介绍了定制的.htaccess网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的这段代码可以正常工作

this code in below work fine

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
#####exclude /cp folder####
RewriteCond %{REQUEST_URI} !^/cp
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /((?!cp)[^.]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [NC,L,QSA,R=301]


RewriteRule ^singer/(.*)$ singer.php?s=$1 [NC,L,QSA]
RewriteRule ^album/(.*)$ album.php?a=$1 [NC,L,QSA]
RewriteRule ^lyric/(.*)$ lyric.php?l=$1 [NC,L,QSA]
RewriteRule ^singers/(.*)$ singers.php?p=$1 [NC,L,QSA]


RewriteRule ^album/(.*)$ album.php?a=$1 [NC,L,QSA]

http://example.com/album.php?a=11 http://example.com/album/11

我想通过PHP考试将其编辑为GET变量

i want edit it to GET variables with PHP exam

http://example.com/album/year/2016 http://example.com/album.php?y=2016

所以我正确了这个代码

RewriteRule ^album/([0-9]+)$ album.php?a=$1 [NC,L,QSA]
RewriteRule ^album/year/([0-9]+)$ album.php?y=$1 [NC,L,QSA]

我看到内部服务器错误此外,尝试使用ErrorDocument处理请求时遇到500内部服务器错误错误.根据要求

i see Internal Server ErrorAdditionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request. on request

http://example.com/album/year/2016 http://example.com/album/20

在所有页面上都可以正常工作

put work fine in all page

新代码

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
#####exclude /cp folder####
RewriteCond %{REQUEST_URI} !^/cp
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /((?!cp)[^.]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [NC,L,QSA,R=301]

RewriteRule ^singer/(.*)$ singer.php?s=$1 [NC,L,QSA]
RewriteRule ^album/([0-9]+)$ album.php?a=$1 [NC,L,QSA]
RewriteRule ^album/year/([0-9]+)$ album.php?y=$1 [NC,L,QSA]
RewriteRule ^lyric/(.*)$ lyric.php?l=$1 [NC,L,QSA]
RewriteRule ^singers/(.*)$ singers.php?p=$1 [NC,L,QSA]

现在我在这行注释7#RewriteRule ^(.*)$ $1.php我的代码在没有获取变量的情况下可以很好地放置页面

now i comment this line 7 #RewriteRule ^(.*)$ $1.php my code work fine put page without get variables stop work

ex http://example.com/singers http://example.com/about

推荐答案

尝试将^(.*)$ $1.php更改为

  RewriteCond %{REQUEST_FILENAME}\.php -f
  RewriteRule ^(.*[^0-9])$ $1.php

这篇关于定制的.htaccess网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:58