我正在尝试创建.htaccess规则来解决所有问题,这就是我所拥有的:
RewriteEngine on
Options -Multiviews
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^ru\/index\.php$ "http\:\/\/www\.example\.com\/ru\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^en\/index\.php$ "http\:\/\/www\.example\.com\/en\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^it\/index\.php$ "http\:\/\/www\.example\.com\/it\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^fr\/index\.php$ "http\:\/\/www\.example\.com\/fr\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^de\/index\.php$ "http\:\/\/www\.example\.com\/de\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^uk\/index\.php$ "http\:\/\/www\.example\.com\/uk\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^es\/index\.php$ "http\:\/\/www\.example\.com\/es\/" [R=301,L]
RewriteCond %{THE_REQUEST} \.php [NC]
RewriteRule \.php$ - [L,R=404,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
ErrorDocument 404 /en/404.php
ErrorDocument 403 /error_page.html
ErrorDocument 500 /error_page.html
使用这些规则我仍有问题: 当我尝试使用.php访问该页面时出现错误: http://www.example.com/en/corniglia.php 但我更喜欢在没有扩展名的情况下重定向到页面。当我解决这个问题 - 别的东西刹车..
答案 0 :(得分:0)
以这种方式使用您的代码:
ErrorDocument 404 /en/404.php
ErrorDocument 403 /error_page.html
ErrorDocument 500 /error_page.html
RewriteEngine on
Options -Multiviews
RewriteCond %{HTTP_HOST} ^(www\.)?incinqueterre\.com$ [NC]
RewriteRule ^(ru|en|it|fr|de|uk|es)/index\.php$ /$1/ [R=301,L,NC]
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?/] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]