Htaccess重定向规则问题

时间:2015-12-29 14:02:17

标签: php wordpress apache .htaccess mod-rewrite

我的服务器人员无法解决我的问题。我在根文件夹上运行Wordpress。我不想拥有英语的文件夹语言。

https://domain.com/account/t/

https://domain.com/fr/account/t/

工作正常,同样适用于:

https://domain.com/auth/

但是

https://domain.com/fr/account/t/myaccount/ 

工作正常但不是

https://domain.com/account/t/myaccount/

网址相同:

https://domain.com/fr/account/t/tests/ 

工作正常但不是

https://domain.com/account/t/test/

重定向到www.domain.com ...

有人有想法吗?这是我的htaccess文件:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^([^/]*)/auth/$ /auth/?lang=$1 [L]
RewriteRule ^([^/]*)/auth/login$ /auth/login.php?lang=$1 [L]
RewriteRule ^([^/]*)/auth/logout$ /auth/logout.php?lang=$1 [L]
RewriteRule ^([^/]*)/auth/registration$ /auth/registration_form.php?lang=$1 [L]
RewriteRule ^([^/]*)/auth/password-forgotten$ /auth/forgot_form.php?lang=$1 [L]
RewriteRule ^([^/]*)/auth/reset$ /auth/reset.php?lang=$1 [L]
RewriteRule ^([^/]*)/auth/activate$ /auth/activate.php?lang=$1 [L]
RewriteRule ^([^/]*)/account/$ /account/?lang=$1 [L]
RewriteRule ^([^/]*)/account/t/$ /account/t/?lang=$1 [L]
RewriteRule ^([^/]*)/account/t/jobs/$ /account/t/jobs.php?lang=$1 [L]
RewriteRule ^([^/]*)/account/t/myaccount/$ /account/t/myaccount.php?lang=$1 [L]
RewriteRule ^([^/]*)/account/t/([^/]*)$ /account/t/?lang=$1&step=$2 [L]
RewriteRule ^([^/]*)/account/t/tests/$ /account/t/testspage.php?lang=$1 [L]
RewriteRule ^([^/]*)/account/c/$ /account/c/?lang=$1 [L]
RewriteRule ^([^/]*)/account/c/([^/]*)$ /account/c/?lang=$1&step=$2 [L]


RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

1 个答案:

答案 0 :(得分:0)

在您的代码中,即使[^/]*不是语言标识符,RewriteRule ^((fr|de|es|it)/)?(.*) /$3.php?lang=$2 也会匹配所有内容。有时你会匹配需要成为脚本名称一部分的东西。

如果您使用此...

fatal error C1001: An internal error has occurred in the compiler.
  (compiler file 'f:\dd\vctools\compiler\utc\src\p2\main.c', line 246)
   To work around this problem, try simplifying or changing the program near the locations listed above.
  Please choose the Technical Support command on the Visual C++
   Help menu, or open the Technical Support help file for more information
    link!InvokeCompilerPass()+0x2d4bd
    link!DllGetC2Telemetry()+0xae663

您只匹配列出的支持语言之一。此外,这种通用方法意味着您只需要1个重写,而不是每个PHP脚本需要1个。