简体   繁体   English

HTAccess 301随条件重定向

[英]Htaccess 301 redirect with conditions

I have the following code: 我有以下代码:

RewriteEngine On


# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^category/(.*)$ /searchPage.php?crs_category=$1 [L,NC,QSA]
RewriteCond %{REQUEST_URI} !^/searchPage.php
RewriteRule ^ index.php [QSA,L]

This works great when I type category/business , but I also want the url to be written if someone type the old url such as searchPage.php?crs_category=business to be redirected as category/business with a 301 code letting the SEO knows that this is the new address. 当我输入这个伟大的工程category/business ,但我也想,如果有人输入旧的URL,如URL被写入searchPage.php?crs_category=business重定向为category/business用301码让SEO知道这是新地址。

Note: The reason why there is the 注意:之所以存在

RewriteCond %{REQUEST_URI} !^/searchPage.php

condition is because I am using the Slim framework and where I want all request to be redirected to index with the exception of the searchPage for routing. 条件是因为我使用的是Slim框架,并且我希望将所有请求重定向到索引,但不包括用于路由的searchPage。

Thanks in advance. 提前致谢。

Add this right under the commented out RewriteBase / 在注释掉的RewriteBase /下添加此权限

RewriteCond %{THE_REQUEST} /searchPage\.php\?crs_category=([^&\ ]+)
RewriteRule ^ /category/%1? [L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM