基本或相对路径don';无法使用.htaccess重写规则
使用.htaccess,我将以以下方式重写url:基本或相对路径don';无法使用.htaccess重写规则,.htaccess,mod-rewrite,url-rewriting,path,url-redirection,.htaccess,Mod Rewrite,Url Rewriting,Path,Url Redirection,使用.htaccess,我将以以下方式重写url: Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{QUERY_STRING} !(^|&)lang=[a-z]{2}(&|$) [NC] RewriteCond %{REQUEST_URI} !^/(en|it) [NC] RewriteRule ^(?:[a-z]{2}/
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !(^|&)lang=[a-z]{2}(&|$) [NC]
RewriteCond %{REQUEST_URI} !^/(en|it) [NC]
RewriteRule ^(?:[a-z]{2}/)?(.*)$ /en/$1 [L,NC,R]
RewriteRule ^([a-z]{2})/(.*)$ /index.php?lang=$1&page=$2 [L,NC,QSA]
要遵循此条件:
http://website.com -> http://website.com/en
http://website.com/en -> http://website.com/en
http://website.com/it -> http://website.com/it
http://website.com/de -> http://website.com/en
有关更多信息,请参阅
现在的问题是当我必须访问一些资产时。例如,我必须加载css/styles.css
我试图通过添加基准来更改基准位置以提供绝对路径:
<base href="http://website.com/">
浏览器以正确的方式请求文件:
Request URL:http://website.com/css/styles.css
Status Code:302 Found
但是我没有得到任何文件,响应头是:
Location:http://website.com/en/css/styles.css
如何解决此问题?您不需要重定向资产。根据站点的工作方式,您可以排除对某些目录的请求,也可以排除对现有资源(如文件或目录)的请求: 或
第一个解决方案是完美的!有没有办法一次包含/css/文件夹及其所有子目录?我也有一些问题..它与css一起工作,但不与其他文件,如imgs或js,我得到了一个404
Location:http://website.com/en/css/styles.css
RewriteCond %{QUERY_STRING} !(^|&)lang=[a-z]{2}(&|$) [NC]
RewriteCond %{REQUEST_URI} !^/(en|it) [NC]
RewriteCond %{REQUEST_URI} !^/css
RewriteRule ^(?:[a-z]{2}/)?(.*)$ /en/$1 [L,NC,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !(^|&)lang=[a-z]{2}(&|$) [NC]
RewriteCond %{REQUEST_URI} !^/(en|it) [NC]
RewriteRule ^(?:[a-z]{2}/)?(.*)$ /en/$1 [L,NC,R]