微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 htaccess 地址重写时显示错误

如何解决在 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]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。