小编miq*_*uel的帖子

多语言网站的.htaccess规则

我正在重新设计PHP多语言网站的URL(en | es | de | fr | ru).网站的URL是这样的:

www.mysite.com/page
www.mysite.com/page/subpage1
www.mysite.com/page/subpage1/subpage2
www.mysite.com/page/subpage1/subpage2/subpage3
Run Code Online (Sandbox Code Playgroud)

最多四个级别的子目录(产品,子产品等).语言作为GET参数传递:

www.mysite.com/page?lang=es
Run Code Online (Sandbox Code Playgroud)

要么

www.mysite.com/page/subpage1/subpage2?lang=de
Run Code Online (Sandbox Code Playgroud)

目前的.htaccess是这样的:

Options +FollowSymlinks +MultiViews -Indexes
RewriteEngine on

RewriteBase /

# Redirect all versions of homepage to www.mysite.com
RewriteCond %{REQUEST_URI} ^/index\.html$
RewriteRule ^index.html$ http://www.mysite.com/ [R=301,L]

# Redirect non-www to www traffic
RewriteCond %{HTTP_HOST} !^(www\.mysite\.com)?$
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

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

#Remove php extension
RewriteCond %{REQUEST_URI} ^(.*).php$
RewriteRule ^(.*)$ %1 [R=301,QSA] 

#Here I have a lot of 301 redirections, I ommit …
Run Code Online (Sandbox Code Playgroud)

php regex .htaccess mod-rewrite multilingual

5
推荐指数
1
解决办法
4159
查看次数

删除友好URL的.php扩展名(明确写入)

htaccess删除我网站文件的.php扩展名.

RewriteEngine on
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ $1.php [L,QSA]
Run Code Online (Sandbox Code Playgroud)

现在,如果我去我的网站

www.mysite.com/home
Run Code Online (Sandbox Code Playgroud)

工作正常,它重定向到home.php但URL仍然友好.

但是,如果我写这个URL:

www.mysite.com/home.php
Run Code Online (Sandbox Code Playgroud)

提供home.php,URL不友好.

我该如何避免这种行为?我希望如果用户写www.mysite.com/home.php,则URL栏中显示的URL为www.mysite.com/home

php .htaccess mod-rewrite friendly-url

4
推荐指数
3
解决办法
8986
查看次数

标签 统计

.htaccess ×2

mod-rewrite ×2

php ×2

friendly-url ×1

multilingual ×1

regex ×1