首页 文章

Mod Rewrite file.php?串起来

提问于
浏览
4

我的旧网站有这样的链接:

http://domain.com/image.php?690

我想将其改为:

http://domain.com/old690

我尝试了很多不同的规则,fe . :

RewriteRule ^ image.php?( . )old $ 1 [L]

编辑:所有规则如下:

RewriteEngine On RewriteRule ^ admin /(.*)ninja-admin / $ 1 [L] RewriteRule ^ index.php $ - [L] RewriteCond%!-f RewriteCond%!-d RewriteRule . index.php [L] RewriteRule ^ image.php \?( . )old $ 1 [L]

什么是正确的RewriteRule,为什么?

2 回答

  • 0

    你这样做是颠倒的 .

    把这段代码放在你的htaccess中

    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^old([0-9]+)$ image.php?$1 [L]
    RewriteRule ^admin/(.*)$ ninja-admin/$1 [L]
    RewriteRule ^index\.php$ - [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
    

    您的图像规则如下

    RewriteRule ^old([0-9]+)$ image.php?$1 [L]
    

    它会将 /old123 (其中 123 是一个或多个数字)的每个URL转发到 image.php?123


    编辑:如果你想禁止直接访问 image.php?xxx 那么你可以这样做

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{THE_REQUEST} \s/image\.php\?([0-9]+) [NC]
    RewriteRule ^ old%1 [R=301,L]
    
    RewriteRule ^old([0-9]+)$ image.php?$1 [L]
    RewriteRule ^admin/(.*)$ ninja-admin/$1 [L]
    RewriteRule ^index\.php$ - [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
    
  • 0

    我使用这个 http://example.com/old4444 转发到 http://example.com/image.php?file=4444 .

    此外,浏览器将 http://example.com/old4444 保留在地址栏中 .

    RewriteCond %{QUERY_STRING} !marker  
    RewriteCond %{QUERY_STRING} file=([0-9]+)
    RewriteRule ^/?image.php$ %1? [R=301,L]
    RewriteRule ^/?old([-a-zA-Z0-9_+]+)$ image.php?marker&file=$1 [L]
    

相关问题