【发布时间】:2021-07-02 23:52:36
【问题描述】:
我有 1 页
https://domainsanalytics.com/country.php
我正在传递类似的值
https://domainsanalytics.com/country.php?id=219
我想制作对 SEO 友好的网址,例如
https://domainsanalytics.com/country/219
我试图通过这个来完成
RewriteRule ^(country)/(\d+)/?$ $1.php?id=$2 [L]
但这给了我页面上的错误,例如:https://domainsanalytics.com/country/219
如果我在上面的代码之前添加,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
适合
https://domainsanalytics.com/country
但 404 开启
https://domainsanalytics.com/country/219
我需要帮助以确保两者都能正常工作
https://domainsanalytics.com/country/219
and
https://domainsanalytics.com/country
PS:打开网站时htaccess只有
RewriteRule ^(country)/(\d+)/?$ $1.php?id=$2 [L]
RewriteRule ^(tld)/(\d+)/?$ $1.php?id=$2 [L]
RewriteRule ^(registrar)/(\d+)/?$ $1.php?id=$2 [L]
和截图
编辑
RewriteEngine ON
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(country)/(\d+)/?$ $1.php?id=$2 [L]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(tld)/(\d+)/?$ $1.php?id=$2 [L]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(registrar)/(\d+)/?$ $1.php?id=$2 [L]
那工作...
【问题讨论】:
标签: css apache .htaccess mod-rewrite friendly-url