国防部重写file.php?串

Mac*_*ted 5 .htaccess mod-rewrite

我有这样的旧网站链接:

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

我想将其更改为:

http://domain.com/old690

我尝试了许多不同的规则,例如:

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

编辑:所有规则看起来像:

RewriteEngine开

RewriteRule ^ admin /(.*)ninja-admin / $ 1 [L]

RewriteRule ^ index.php $-[L]

RewriteCond%{REQUEST_FILENAME}!-f

RewriteCond%{REQUEST_FILENAME}!-d

RewriteRule。index.php [L]

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

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

Jus*_*man 1

你这样做是颠倒了。

将此代码放入您的 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]
Run Code Online (Sandbox Code Playgroud)


您的图像的规则如下

RewriteRule ^old([0-9]+)$ image.php?$1 [L]
Run Code Online (Sandbox Code Playgroud)

它将把每个 url /old123(其中123是一个或多个数字)转发到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]
Run Code Online (Sandbox Code Playgroud)