Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 如何从一个url重定向到另一个url?_.htaccess_Mod Rewrite_Prestashop_Prestashop 1.6 - Fatal编程技术网

.htaccess 如何从一个url重定向到另一个url?

.htaccess 如何从一个url重定向到另一个url?,.htaccess,mod-rewrite,prestashop,prestashop-1.6,.htaccess,Mod Rewrite,Prestashop,Prestashop 1.6,Web正在使用prestashop 1.4运行,因此升级到1.6后,url会有所不同 在prestashop 1.4中,我是 web.com/category.php?id_category=5980 但在prestashop 1.6中,我是 web.com/index.php?id_category=5980&controller=category 所以问题是,是否可以使用Apache的mod_rewrite中的某种重写规则或其他方法 因为当我尝试在.htaccess中使用时: R

Web正在使用prestashop 1.4运行,因此升级到1.6后,url会有所不同

在prestashop 1.4中,我是

web.com/category.php?id_category=5980
但在prestashop 1.6中,我是

web.com/index.php?id_category=5980&controller=category
所以问题是,是否可以使用Apache的mod_rewrite中的某种重写规则或其他方法

因为当我尝试在.htaccess中使用时:

RewriteEngine On
Redirect 301 ^category.php?id_category=5980 /index.php?id_category=5980&controller=category
我有404页

或者我可能需要编写一些php代码来手动重定向它

请给出正确的解决方案

    <FilesMatch "\.tpl$">
Deny from all
</FilesMatch>

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums

<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>

RewriteEngine on


#Domain: www.web.com
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api$ api/ [L]

RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]

# Images
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]

# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>

AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/x-font-woff .woff
<IfModule mod_headers.c>
    <FilesMatch "\.(ttf|ttc|otf|eot|woff|svg)$">
        Header add Access-Control-Allow-Origin "*"
    </FilesMatch>
</IfModule>

#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404

# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again

# start ~ module watermark section
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}*/admin1/*'"
RewriteRule [0-9/]+/[0-9]+\.jpg$ - [F]
</IfModule>
# end ~ module watermark section

全盘否定
#~~开始~~不要删除此注释,当再次生成.htaccess时,Prestashop将自动将代码保留在此注释之外
#.htaccess由PrestaShop电子商务开源解决方案自动生成
# http://www.prestashop.com - http://www.prestashop.com/forums
SetEnv HTTP_MOD_重写
重新启动发动机
#域名:www.web.com
重写规则[E=REWRITEBASE://]
重写规则^api$api/[L]
重写规则^api/(.*)$%{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1[QSA,L]
#图像
重写规则^([0-9])(\-[\u a-zA-Z0-9-]*)?([0-9]+)?/.+\.jpg$%{ENV:REWRITEBASE}img/p/$1/$2$3.jpg[L]
重写规则^([0-9])([0-9])(\-[\u a-zA-Z0-9-]*)?([0-9]+)?/.+\.jpg$%{ENV:REWRITEBASE}img/p/$1/$2/$3$4.jpg[L]
重写规则^([0-9])([0-9])([0-9])(\-[\u a-zA-Z0-9-]*)?([0-9]+)?/.jpg$%{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg[L]
重写规则^([0-9])([0-9])([0-9])([0-9])(\-[\u a-zA-Z0-9-]*)?([0-9]+)?/.jpg$%{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg[L]
重写规则^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[\u a-zA-Z0-9-]*)?([0-9]+)?/.jpg$%{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg[L]
重写规则^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[\u a-zA-Z0-9-]*)?([0-9]+)/.jpg$%{ENV:REWRITEBASE}img/p/$1/$2/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg[L]
重写规则^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[u a-zA-Z0-9-])?([0-9]+)/。+\.jpg$%{ENV:REWRITEBASE}img/p/$1/$3/$4/$6/$7/$1$2$3$4$5$7$8$9.jpg[L]
重写规则^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[u a-zA-Z0-9-]*)?([0-9]+)/。+\.jpg$%{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$8/$1$2$3$4$6$7$8/$9$10.jpg]
重写规则^c/([0-9]+)(\-[\.*U a-zA-Z0-9-]*)([0-9]+)?/.+\.jpg$%{ENV:REWRITEBASE}img/c/$1$2$3.jpg[L]
重写规则^c/([a-zA-Z-]+)([0-9]+)?/.+\.jpg$%{ENV:REWRITEBASE}img/c/$1$2.jpg[L]
#IE和fancybox的AlphaImageLoader
重写规则^images\u ie/?([^/]+)\(jpe?g | png | gif)$js/jquery/plugins/fancybox/images/$1.$2[L]
#调度员
RewriteCond%{REQUEST_FILENAME}-s[或]
RewriteCond%{REQUEST_FILENAME}-l[或]
RewriteCond%{REQUEST_FILENAME}-d
重写规则^.*$-[NC,L]
重写规则^.*${ENV:REWRITEBASE}index.php[NC,L]
AddType应用程序/vnd.ms-fontobject.eot
AddType字体/ttf.ttf
AddType字体/otf.otf
AddType应用程序/x-font-woff.woff
标题添加访问控制允许源“*”
#如果未启用“重写模式”
ErrorDocument 404/index.php?控制器=404
#~~end~~不要删除此注释,当再次生成.htaccess时,Prestashop将自动将代码保留在此注释之外
#开始~模块水印部分
选项+FollowSymLinks
重新启动发动机
RewriteCond expr“!%{HTTP_REFERER}-strmatch'*://%{HTTP_HOST}*/admin1/*”
重写规则[0-9/]+/[0-9]+\.jpg$-[F]
#结束模块水印部分

您可以在
上的重写引擎下方使用此规则:

RewriteRule ^category\.php$ /sc16/index.php?controller=category [L,QSA,NC,R=301]

由于使用了
QSA
其他查询参数
id\u category=5980
将被带入新的URL。

我发现的另一个解决方案是:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^id_category=([0-9]+)$
RewriteRule ^category.php?$ /sc16/index.php?id_category=%1&controller=category [R=301,L]

RewriteCond %{QUERY_STRING} ^id_product=([0-9]+)$
RewriteRule ^product.php?$ /index.php?id_product=%1&controller=product [R=301,L]

我还发现:重写规则^category\.php([0-9]*)$/index.\php$1[R=301,L]但我不知道如何将&controller=category添加到它?在本地计算机上使用xamp()它将我重定向到localhost/是的,它在那里。整个.htaccess列表被添加到主问题中。@anubhava hi我面临着相同类型的问题。需要你的帮助嗨,我有这个权限。我想重写我的url从到和从到。。。但我似乎失败了,它不起作用了@anubhava