在 htaccess 地址重写时显示错误

问题描述

我想转换网址:

/tld/?=com/tld/com/

我的完整 htaccess 代码如下:

Options -Indexes

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+(whois|error)(?:\.PHP)?[\s?] [NC]
RewriteRule ^ /%1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f    
RewriteCond %{REQUEST_URI} !\.(PHP?|jpg|gif|png|css|js|html|json|xml|eot|svg|ttf|woff|woff2|zip|csv|xlsx|webp|txt|gz|rar)$ [NC]
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.PHP -f
RewriteRule ^(.+?)/?$ $1.PHP [L]

##### Rewite #####

##RewriteRule ^([^/]*)\$ /tld.PHP?tld=$1 [L]
RewriteRule ^([^/]+)\$ /tld.PHP?tld=$1 [L] 

但它显示 500 错误所以请帮忙

解决方法

就这样吧:

Options -Indexes -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+(whois|error)(?:\.php)?[\s?] [NC]
RewriteRule ^ /%1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f    
RewriteCond %{REQUEST_URI} !\.(php?|jpg|gif|png|css|js|html|json|xml|eot|svg|ttf|woff|woff2|zip|csv|xlsx|webp|txt|gz|rar)$ [NC]
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]

# ignore all rules below this for files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{ENV:REDIRECT_STATUS} .
RewriteRule ^ - [L]

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^tld/([\w-]+)/?$ tld.php?tld=$1 [L,QSA]