问题
this code in below work fine
old code
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
i want edit it to GET variables with PHP exam
http://example.com/album/year/2016 http://example.com/album.php?y=2016
so i right this code
RewriteRule ^album/([0-9]+)$ album.php?a=$1 [NC,L,QSA]
RewriteRule ^album/year/([0-9]+)$ album.php?y=$1 [NC,L,QSA]
i see Internal Server Error Additionally, 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 or http://example.com/album/20
put work fine in all page
new code
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]
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:
try change ^(.*)$ $1.php
to
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*[^0-9])$ $1.php
来源:https://stackoverflow.com/questions/39541836/customized-htaccess-url