gpt4 book ai didi

php - 使用动态 URL 的 Htaccess 301 重定向

转载 作者:搜寻专家 更新时间:2023-10-31 21:36:24 26 4
gpt4 key购买 nike

我需要将带有参数的动态 URL 重定向到子文件夹 URL。源 URL 的长度/级别可能有所不同。

一个例子是:

来源:

http://www.example.com/dir/?lang=en

期望:

http://www.example.com/dir/en

另一个是:

来源:

http://www.example.com/dir/subdir/?lang=en

期望:

http://www.example.com/dir/subdir/en

我使用的是 WordPress,所以我的 .htaccess 中有一些现有代码,有问题的重定向需要使用这些代码。我现有的 .htaccess 看起来像这样:

RewriteEngine On
RewriteBase /

RewriteRule ^index\.php$ - [L]

RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

我尝试搜索整个网络,但是,似乎没有适合这种特殊情况的解决方案/答案。有高手帮忙吗?

最佳答案

通过 httpd.conf 启用 mod_rewrite 和 .htaccess,然后将此代码放入 DOCUMENT_ROOT 目录下的 .htaccess 中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} !^lang=.+ [NC]
RewriteRule ^(.+?)/([^/]+)/?$ $1/?lang=$2 [L,QSA]

关于php - 使用动态 URL 的 Htaccess 301 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18450860/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com