【问题标题】:How to remove numbers from url如何从网址中删除数字
【发布时间】:2019-10-19 15:29:43
【问题描述】:

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    您可以像这样使用 3-1 规则:

    RewriteEngine On
    RewriteBase /test/ 
    
    RewriteRule ^[0-9]+-(.+?)/?$ $1 [L,R=301]
    
    # rest of rules
    

    【讨论】:

    • 我在本地服务器上测试了这段代码,我写如下:- RewriteEngine On RewriteBase /test/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(. *)$ $1.php [NC,L] RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC] RewriteRule ^ %1 [R =301,L] RedirectMatch 301 ^/[0-9]+-(test)/?$ /$1
    • 我的页面是87-test.php
    • 你的网址是http://example.com/87-test.php 还是http://example.com/test/87-test.php
    • ok 查看更新的代码。如图所示,此规则必须是RewriteBase /test/ 规则下方的第一条规则。
    • 是的,它可以正常工作,但是此代码正在重定向页面以测试显示 404 错误的位置。我只想隐藏那些数字
    猜你喜欢
    • 1970-01-01
    • 2013-05-17
    • 2021-03-17
    • 2020-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    • 2014-06-25
    相关资源
    最近更新 更多