【问题标题】:Giving error with dot in url在 url 中使用点给出错误
【发布时间】:2016-04-06 10:54:32
【问题描述】:

我的 url 有问题,当 dot 出现在 url 中时,它会给出 404 错误。

网址:http://example.com/Samsung-Galaxy-Mega-5.8

我在 htaccess 中使用了一些代码,但它不能正常工作。

RewriteRule ^([a-zA-Z_\-]+)/?([a-zA-Z0-9\-=&_@\.]*)$ /$1.php?$2 [QSA,L]

编辑(从评论中复制):

RewriteEngine on 
Options -Indexes 
#RewriteCond %{HTTP_HOST} ^([a-z0-9-A-Z_]*).([a-z]*)$ 
#RewriteRule ^(.*)$ %1.%2/$1 [L,R=301] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
#RewriteRule ^([a-zA-Z0-9_-]+)$ show_mobile.php?bid=$1&brandname=$2 
RewriteRule ^([a-zA-Z0-9\-]+)-([a-zA-Z0-9\-]+)$ show_mobile.php?bid=$2&brandname=$1

【问题讨论】:

  • 向我们展示更多您的 [.htaccess]。这本身正在寻找您提供的示例 URL 中不存在的 /?
  • 这里是我的 htaccess 完整代码: RewriteEngine on Options -Indexes #RewriteCond %{HTTP_HOST} ^([a-z0-9-A-Z_]*).([a-z]*)$ # RewriteRule ^(.*)$ %1.%2/$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d #RewriteRule ^([a-zA-Z0-9_-]+)$ show_mobile.php?bid=$1&brandname=$2 RewriteRule ^([a-zA-Z0-9\-]+)-([a-zA-Z0-9\-]+)$ show_mobile.php?bid=$2&brandname =$1

标签: .htaccess url


【解决方案1】:

我想以下内容应该可以帮助您:

^([a-z0-9\-\.]+)\-([a-z0-9\-\.]+)$i

(基于评论中的 .htaccess)

https://regex101.com/r/jZ9sP3/1

您不允许使用句号,也没有在捕获规则之间转义连字符。

尾部i 不区分大小写,所以你不需要做a-zA-Z

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-17
    • 2011-06-23
    • 1970-01-01
    • 2014-05-19
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 2011-05-29
    相关资源
    最近更新 更多