简体   繁体   English

.htaccess RewriteRule重定向

[英].htaccess RewriteRule Redirect

I have two websites, xyz.com and testsite.com (just for example). 我有两个网站xyz.com和testsite.com(仅作为示例)。 I've linked my domain xyz.com to testsite.com/content. 我已经将我的域xyz.com链接到testsite.com/content。 My testsite.com/content features a .htaccess which features the following code meant to remove the .php extension from the URL: 我的testsite.com/content具有.htaccess,具有以下代码,旨在从URL中删除.php扩展名:

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

It works perfectly fine on the source website; 它在源网站上运行良好; however, it shoots off a 404 error in the xyz.com and references /content/content/login instead of /content/login in the testsite.com. 但是,它会在xyz.com中引发404错误,并在testsite.com中引用/ content / content / login而不是/ content / login。 How do I fix this? 我该如何解决?

Add RewriteBase / to the code so like this 像这样将RewriteBase /添加到代码中

Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

If it doesn't work like this, try adding the rewritebase under the options or at the top of the htaccess. 如果这样不起作用,请尝试在选项下或htaccess顶部添加rewritebase。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM