.htaccess 如何重写url的一部分

.htaccess 如何重写url的一部分,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,假设我有URL http://www.example.com/se/products/details/23 http://www.example.com/se/company/about http://www.example.com/se/customers/europe/john-doe etc. 我想让他们把重写成 http://www.example.com/en/products/details/23 http://www.example.com/en/company/about ht

假设我有URL

http://www.example.com/se/products/details/23
http://www.example.com/se/company/about
http://www.example.com/se/customers/europe/john-doe
etc.
我想让他们把重写成

http://www.example.com/en/products/details/23
http://www.example.com/en/company/about
http://www.example.com/en/customers/europe/john-doe
etc
这意味着,无论使用哪种语言,它们都会被重写为
en
,它们会在地址栏中看到各自的语言,但页面是从“en”开始的服务器

我的规则是这样的

# Pass through the original path as a query parameter, and retain the existing parameters.
    RewriteCond %{REQUEST_URI} ^(.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* framework/main.php?url=%1 [QSA]

    RewriteRule ^se/(.+?)\/?$ /en/$1 [L]
该项目基于
SilverStripe
框架

而这不起作用,显示404页面未找到错误

我们怎样才能做到这一点呢?

像这样试试

Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^se/(.+?)\/?$ /en/$1 [L]


重新排列您的规则,如下所示:

RewriteEngine On

RewriteRule ^se(/.*)?$ en$1 [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ framework/main.php?url=%{REQUEST_URI} [L,QSA]

“这没用”。会发生什么?你能给我们看一下重写日志吗?@undone,它显示404页找不到错误重写日志呢?你能把日志放在这里吗?你的.htaccess中还有其他规则吗?还有你的.htaccess的位置是什么?@undone重写日志文件是空的,没有任何问题。这不起作用,第一个给出500错误,第二个导致404错误。两件事,我假设您在根目录中应用这些规则,然后您必须处理en/text/text的重写,以及对原始url的其他内部重写,例如
page.php?lang?=en&detail=23
请检查或提供原始url。实际上,该项目基于
SilverStripe
框架,因此,没有您指定的原始url。Silverstripe有自己的URL路由方式。
RewriteEngine On

RewriteRule ^se(/.*)?$ en$1 [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ framework/main.php?url=%{REQUEST_URI} [L,QSA]