.htaccess重写URL的部分

.htaccess重写URL的部分,.htaccess,mod-rewrite,url-rewriting,.htaccess,Mod Rewrite,Url Rewriting,我有两个要求: 我想在URL中将comp组件/testcomp重写为comp https://www.website.com/component/testcomp应如下所示: https://www.website.com/comp在URL中 所有来自website.com的请求都应该被301重定向到https://www.website.com 以下是我的.htaccess文件的内容: IndexIgnore * Options +FollowSymlinks Options -Ind

我有两个要求:

  • 我想在URL中将
    comp组件/testcomp
    重写为
    comp
  • https://www.website.com/component/testcomp
    应如下所示:
    https://www.website.com/comp
    在URL中

  • 所有来自
    website.com
    的请求都应该被301重定向到
    https://www.website.com
  • 以下是我的
    .htaccess
    文件的内容:

       IndexIgnore *
    
    Options +FollowSymlinks
    Options -Indexes
    
    
    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
    RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
    RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
    RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
    RewriteRule .* index.php [F]
    
    
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteCond %{REQUEST_URI} !^/index\.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php [L]
    
    
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^website\.com$ [NC]
    RewriteRule ^(.*)$ https://www.website.com/$1 [R=301,L]
    
    IndexIgnore*
    选项+FollowSymlinks
    选项-索引
    重新启动发动机
    RewriteCond%{QUERY\u STRING}base64\u encode[^(]*\([^)]*\)[或]
    重写cond%{QUERY_STRING}(|%3E)[NC,或]
    重写条件%{QUERY\u STRING}全局(|\[|\%[0-9A-Z]{0,2})[或]
    重写条件%{QUERY\u STRING}\u请求(|\[|\%[0-9A-Z]{0,2})
    重写规则。*index.php[F]
    重写规则。*-[E=HTTP\U授权:%{HTTP:AUTHORIZATION}]
    重写cond%{REQUEST_URI}!^/index\.php
    重写cond%{REQUEST_FILENAME}!-f
    重写cond%{REQUEST_FILENAME}!-d
    重写规则。*index.php[L]
    重写基/
    RewriteCond%{HTTP_HOST}^website\.com$[NC]
    重写规则^(.*)$https://www.website.com/$1[R=301,L]
    
    我怎么能这样做?我尝试添加重写规则,但它不起作用。请告诉我重写规则&我应该将其放置在哪里。

    要将“/component/testcomp”重写为“comp”,我认为您必须用R标记它,或使用R=301使其成为永久规则。不过,我感觉您可能需要调整其他规则

    RewriteRule ^component/testcomp/(.*)$ /comp/$1 [L,R]
    
    或使其永久化:

    RewriteRule ^component/testcomp/(.*)$ /comp/$1 [L,R=301]
    
    要将“/component/testcomp”重写为“comp”,我认为您必须用R标记它,或者使用R=301使其成为永久性的。然而,我感觉您可能需要调整其他规则

    RewriteRule ^component/testcomp/(.*)$ /comp/$1 [L,R]
    
    或使其永久化:

    RewriteRule ^component/testcomp/(.*)$ /comp/$1 [L,R=301]
    
    请尝试以下操作:

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /component/test(comp)(\S*) [NC]
    RewriteRule ^ /%1 [R=301,L,QSA]
    
    然后呢,

    RewriteRule ^comp(.*)$ /component/testcomp$1 [QSA,NC,L]
    
    请尝试以下操作:

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /component/test(comp)(\S*) [NC]
    RewriteRule ^ /%1 [R=301,L,QSA]
    
    然后呢,

    RewriteRule ^comp(.*)$ /component/testcomp$1 [QSA,NC,L]
    

    在.htaccess的最后添加了它,但它不起作用。您可以告诉我应该将其放置在哪里吗?在.htaccess的最后添加了它,但它不起作用。您可以告诉我应该将其放置在哪里吗?