Php htaccess 301重定向到语言子目录
我更改网站url以接受不同的语言,因此,我将网站内容移动为默认语言 从:www.site.com到:www.site.com/en 现在,我从php执行重定向,如果Php htaccess 301重定向到语言子目录,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,我更改网站url以接受不同的语言,因此,我将网站内容移动为默认语言 从:www.site.com到:www.site.com/en 现在,我从php执行重定向,如果$\u GET['lang']不存在或$\u GET['path']存在,则重定向到site.com/en或site.com/en/(path),但我认为从根目录到文件夹的301重定向更好 我怎么写这个规则 这是我的htaccess文件: RewriteEngine on RewriteBase / RewriteCond %{HT
$\u GET['lang']
不存在或$\u GET['path']
存在,则重定向到site.com/en或site.com/en/(path),但我认为从根目录到文件夹的301重定向更好
我怎么写这个规则
这是我的htaccess文件:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^download/(.*)$ php/download.php?id=$1 [L]
# with language
RewriteRule ^([a-z]{2})/p/(.*)$ single.php?lang=$1&hash=$2 [L]
RewriteRule ^([a-z]{2})$ index.php?lang=$1 [L,NC,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ index.php?path=$1 [NC,L,QSA]
谢谢如果我的理解是正确的,这将满足您的要求
已更新。htaccess
(带注释以便于理解)
需要澄清一下。URL的示例是什么,以及应该如何处理这些URL。
RewriteEngine on
RewriteBase /
# If the hostname is a `www` subdomain, redirect to the parent domain
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Internal rewrite of Download request URL to download PHP script
RewriteRule ^download/(.*)$ php/download.php?id=$1 [L]
# If request path is just root `/` (redirect to default language site)
RewriteRule ^$ /en [R=301,L]
# If request path is a language code,
# internally rewrite to index.php with `lang` query paramater
RewriteRule ^([a-z]{2})$ index.php?lang=$1 [L,NC,QSA]
# If request path begins with lang code and has a hash segment,
# internally rewrite to single.php with `lang` and `hash` query parameters
RewriteRule ^([a-z]{2})/p/(.*)$ single.php?lang=$1&hash=$2 [L]
# If request path begins with lang code and has additional segements
RewriteRule ^([a-z]{2})/(.*)$ index.php?lang=$1&path=$2 [NC,L,QSA]
# For every other request path not having a language code,
# if path is not an existing file or directory,
# redirect to a path prefixing default lang code before the requested path
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /en/$1 [NC,L,R=301]