我想重写如下示例中的 URL:
http://www.domain.com/index.php <=> http://www.domain.com
http://www.domain.com/index.php?lang=de <=> http://www.domain.com/de
http://www.domain.com/index.php?p1=something <=> http://www.domain.com/something
http://www.domain.com/index.php?lang=de¶m1=something <=> http://www.domain.com/de/something
http://www.domain.com/index.php?p1=something&p2=something-else <=> http://www.domain.com/something/something-else
http://www.domain.com/index.php?lang=de&p1=something&p2=something-else <=> http://www.domain.com/de/something/something-else
规则应该允许添加其他语言环境,而不仅仅是 DE。此外,当用户访问例如http://domain.com/de/时,应使用 301 将他重定向到http://domain.com/de(因此尾部斜杠不会创建重复的 URL)
你能给我一些帮助吗?非常感谢。
编辑
我试图过滤掉需要的文件夹,然后我被困在第一个参数上
#Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com[nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
#rewrite all physical existing file or folder
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
#allow things that are certainly necessary
RewriteCond %{REQUEST_URI} "/images/" [OR]
RewriteCond %{REQUEST_URI} "/media/" [OR]
RewriteCond %{REQUEST_URI} "/script/" [OR]
RewriteCond %{REQUEST_URI} "/style/"
#rewrite rules
RewriteRule .* - [L]
RewriteRule (.*) index.php?lang=$1 [QSA]
#add trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*[^/]$ /$0/ [L,R=301]
#Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
#Prevent directory listings
Options All -Indexes