Heim >Backend-Entwicklung >PHP-Tutorial >php url 跳转老目录到新目录
一个关于手机的网站,用wordpress基板。
原先的htacess 放在主目录下 /var/www/html
<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteRule ^items/products/(\d+)/(.*)?$ items/products.php?number=$1&name=$2 [QSA,L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule>
<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /2014/RewriteRule ^phone/products/(\d+)/(.*)?$ phone/products.php?number=$1&name=$2 [QSA,L]RewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule (.*) $1.php [L]</IfModule>
<?phpheader("Status: 301 Moved Permanently");header('http://www.example.com/2014/phone/products/'.$_GET['number'].'/'.$_GET['name']);exit;?>
1)header跳转之所以报错,写法错误。header("Location:$url ");
另外里面的$_GET这几个如果不存在,又没有设置报错级别,那么还是容易报错
2)重写文件.htaccess 无需放到 /2014/目录,直接在原来的 / 重写即可
#by default7#zbphp.com<IfModule mod_rewrite.c>RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^items/products/(\d+)/(.+)?$ 2014/phone/products/$1/$2/ [L,R=301]RewriteRule ^2014/phone/products/(\d+)/(.+)?$ phone/products.php?number=$1&name=$2 [PT,QSA,L]RewriteRule (.*) $1.php [L]</IfModule>