htaccess的不工作的IP /〜用户名用户名、工作、htaccess、IP

2023-09-02 11:40:48 作者:喜你为疾 药石无医

下面是我的情况。我试图使用的.htaccess的重写URL,但无论我如何努力,浏览器​​总是显示500错误或404错误。

这是我的code。

  RewriteEngine叙述上
的RewriteBase /〜torinots /测试/
的RewriteCond%{} REQUEST_FILENAME!^(/测试/家)
重写规则^家$的index.php [L]
 

例如路径: HTTP://xx.xx.xx.xx/~username/公测/

请咨询。

更新

我发现这个工作!

  

RewriteEngine叙述上   的RewriteBase /〜torinots   重写规则^测试版/家庭/?$公测/ index.php文件[L,NC]

解决方案

我假设你已经在/〜用户名/公测.htaccess文件,因为你在上面使用的例子相对的路径。有了像下面的规则一个简单的规则将正确内部重写URL,假设在.htaccess文件中没有其他规则越往上的干扰。

 重写规则^家$的index.php [L]
 

如果你想重定向请求到index.php过,那么你就需要prevent发生一个无限循环。您可以使用END标志(2.3.9版本及以上)或THE_REQUEST伎俩。

  #INTERNAL重写,然后停止一切
重写规则^家$的index.php [结束]

#Rewritebase是可能需要重定向
的RewriteBase /〜torinots /测试/

#EXTERNAL重定向
重写规则^指数 .PHP $回家[R = 301,L]
 

  #INTERNAL重写,然后停止一切
重写规则^家$的index.php [L]

#Rewritebase是可能需要重定向
的RewriteBase /〜torinots /测试/

#EXTERNAL重定向
的RewriteCond%{} THE_REQUEST指数 .PHP
重写规则^指数 .PHP $回家[R = 301,L]
 

Here is my case. I'm trying to use .htaccess for rewrite url, but no matter how I try, browser always show 500 error or 404 error.

here is my code.

RewriteEngine On
RewriteBase /~torinots/beta/
RewriteCond %{REQUEST_FILENAME} !^(/beta/home)
RewriteRule ^home$ index.php [L]

example path: http://xx.xx.xx.xx/~username/beta/

Pls advice.

Update

I found this work!

RewriteEngine On RewriteBase /~torinots RewriteRule ^beta/home/?$ beta/index.php [L,NC]

解决方案

I assume you have the .htaccess file in /~username/beta, since you use paths relative to that in the example above. Having a simple rule like the following rule will correctly internally rewrite the url, assuming that no other rules in .htaccess files higher up are interfering.

RewriteRule ^home$ index.php [L]

If you want to redirect a request to index.php too, then you need to prevent an infinite loop from happening. You can either use the END-flag (version 2.3.9 and up) or the THE_REQUEST trick.

#internal rewrite, and then stop everything
RewriteRule ^home$ index.php [END]

#Rewritebase is possibly needed for the redirect
RewriteBase /~torinots/beta/

#external redirect
RewriteRule ^index.php$ home [R=301,L]

or:

#internal rewrite, and then stop everything
RewriteRule ^home$ index.php [L]

#Rewritebase is possibly needed for the redirect
RewriteBase /~torinots/beta/

#external redirect
RewriteCond %{THE_REQUEST} index.php
RewriteRule ^index.php$ home [R=301,L]