Php I';我在重写规则方面有问题
我有一个网站,我正试图开发,我有一些(可能是noob)的问题,让我的重写规则正常工作 基本上,我正在使用codeIgniter框架来开发网站,作为其中的一部分,我创建了一个重写规则来删除URL的index.php部分,除了一些用于图像等的文件夹Php I';我在重写规则方面有问题,php,.htaccess,codeigniter,mod-rewrite,Php,.htaccess,Codeigniter,Mod Rewrite,我有一个网站,我正试图开发,我有一些(可能是noob)的问题,让我的重写规则正常工作 基本上,我正在使用codeIgniter框架来开发网站,作为其中的一部分,我创建了一个重写规则来删除URL的index.php部分,除了一些用于图像等的文件夹 RewriteEngine on RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|shop) RewriteRule ^(.*)$ /TESTSite/index.php/$1 [L] 该网
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|shop)
RewriteRule ^(.*)$ /TESTSite/index.php/$1 [L]
该网站最初有一个当前页面page/facilities/our shop
,这是一个非常基本的页面,有几个到贝宝的链接,可以快速创建一个非常粗糙的店铺页面,因为我们需要一个。然而,现在我已经实现了一个不同的(阅读OpenCart)商店部分,以使其更专业,并允许更多功能等。我已经将OpenCart放置在名为商店
的子目录中。由于我已将/shop
从我的原始重写规则中排除,该商店继续正常工作
然而,我的问题。。。
我希望旧页面page/facilities/our shop
重定向到/shop
,因此工作起来就像我直接导航到那里一样
我尝试了以下方法:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|shop)
RewriteRule ^page/facilities\/our-shop$ /TESTSite/shop/$1 [R,NC,L]
RewriteRule ^(.*)$ /TESTSite/index.php/$1 [L]
及
还有一些其他的变化,但每次我都不能让它工作。有人能给我建议吗
谢谢我想你可以试试以下规则:
RewriteEngine on
RewriteRule TESTSite/page/facilities/our-shop$ /TESTSite/shop/$1 [R=301]
RewriteCond %{REQUEST_URI} !^(index\.php|images|css|js|robots\.txt|shop)
RewriteRule ^TESTSite/page/(.*)$ /TESTSite/index.php/$1 [L]
两件事:
- 使用“重写条件”时,它仅适用于以下规则。所以我重新订了两条线
- 规则中的
之前不需要/
\
检查以调试您的规则。谢谢纪尧姆,我感谢您的回复和帮助。不幸的是,这似乎仍然没有达到我的预期。。页面仍保留在原始页面(旧页面)上。我将数据输入到您建议的工具中,它给出了以下内容:
request=http://localhost/TESTSite/page/facilities/our-shop
.htaccess=RewriteRule^page/facilities/our shop$/TESTSite/shop/$1[R=301]RewriteCond$1^(index\.php | images | css | js | robots\.txt | shop)RewriteRule^(.*)$/TESTSite/index.php/$1[L]
输出URL=http://localhost/TESTSite/page/facilities/our-shop
该站点上的调试数据显示第1行和第2行输出规则行(第3行为空),第4行给出:RewriteCond$1^(index\.php | images | css | js | shop)不支持此变量:$
我有$的问题吗?是不是应该有所不同?第5行显示此规则未满足,因为其中一个条件未满足
您是对的,答案已编辑。抱歉,忘记了您的根文件夹。
RewriteEngine on
RewriteRule TESTSite/page/facilities/our-shop$ /TESTSite/shop/$1 [R=301]
RewriteCond %{REQUEST_URI} !^(index\.php|images|css|js|robots\.txt|shop)
RewriteRule ^TESTSite/page/(.*)$ /TESTSite/index.php/$1 [L]