Apache 如何使用htaccess根据不同的条件重定向?
我似乎不知道如何使用htaccess正确执行重定向 我需要重定向一些类似这样的页面(xxx表示任何字符串):Apache 如何使用htaccess根据不同的条件重定向?,apache,.htaccess,redirect,mod-rewrite,url-rewriting,Apache,.htaccess,Redirect,Mod Rewrite,Url Rewriting,我似乎不知道如何使用htaccess正确执行重定向 我需要重定向一些类似这样的页面(xxx表示任何字符串): website.com/fr=>好的 website.com/en=>website.com/en/page-1[R 301] website.com/en/category-1/xxx=>正常 website.com/en/category-2/xxx=>website.com/en/page-1[R 301] website.com/en/category-3/xxx=>websit
website.com/fr
=>好的website.com/en
=>website.com/en/page-1
[R 301]website.com/en/category-1/xxx
=>正常website.com/en/category-2/xxx
=>website.com/en/page-1
[R 301]website.com/en/category-3/xxx
=>website.com/en/page-1
[R 301](我有多个不同的类别,其中包含所有需要重定向的子页面)请你试试下面的,按照所示的样品写的。请在将这些内容放入htaccess文件后清除浏览器缓存
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/(en)/?$ [NC]
RewriteRule ^(.*)$ /%1/page-1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/en/(category-[23])/[\w-]+/?$ [NC]
RewriteRule ^(.*)$ /en/page-1 [R=301,L]
谢谢这看起来很有效,但似乎有一个问题:它也会用根文件夹重写URL,比如:mywebsite.com/data/webs/public\u html/en/page-1,所以它会在地址栏中添加“data/webs/public\u html/”,这会导致问题。@ThomasMiller,很抱歉没有完全理解它,以防您不想看到URL(后端)在浏览器中,然后从上述规则中删除
R=301
,清除浏览器缓存,然后重试,如果我没有弄错您的问题。需要多长时间?如何清除它(对于其他用户)?一点也不,你根本不能。是的,但是对于外部重定向,它给出了完整的文档根路径,这不是故意的,因为它不起作用。这就是为什么ThomasMiller在他的路径中抱怨data/webs/public\u html/
我们都在这里互相帮助
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/(en)/?$ [NC]
RewriteRule ^(.*)$ /%1/page-1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/en/(category-[23])/[\w-]+/?$ [NC]
RewriteRule ^(.*)$ /en/page-1 [R=301,L]