dst8922
2012-09-22 03:53
浏览 222
已采纳

如果端口不是80,则.htaccess重定向到错误页面

I'm running a portable server through usb stick. The thing is I also have WAMP installed in my local machine and Apache somehow gets started on windows startup, because of some random reason which I don't recall now and it can't be changed. I want to prepare my portable server in situations like this, so closing httpd.exe from process and starting my portable server is not an option. Anyway, because of already active httpd.exe my portable server's WordPress site can only be accessed through localhost:81 - this is a problem as WP site is very dependent on the URL and I don't want to include the url with port on WP database.

Here is what I want to do through .htaccess:

  • On any path except for error.php file check if not port 80
  • If not port 80 redirect to /error.php?code=port

It it possible for it to have priority over WP redirection or URL handling?

In the error.php I provided info on how to manually close httpd.exe and such so my family and friends can access the portable site. It's sort of like a gallery and calender application for events and other such stuff...

Please help? I'm I can't figure it out at all. I know others may not have apache already running, but I want to prepare for such a situation.

Something like the following, but the following doesn't work.

# BEGIN WordPress
<IfModule mod_rewrite.c>
    <If "%{SERVER_PORT} = 80">
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </If>
    <Else>
    RewriteEngine On
    RewriteRule ^(error.php)($|/) - [L]
    RewriteRule ^(.*)$ /error.php?code=port [L]
    </Else>
</IfModule>
# END WordPress

图片转代码服务由CSDN问答提供 功能建议

我正在运行便携式服务器通过usb棒。 问题是我也在我的本地机器上安装了WAMP,并且Apache以某种方式在Windows启动时启动,因为一些随机的原因我现在不记得并且它无法更改。 我希望在这种情况下准备我的便携式服务器,因此从进程中关闭httpd.exe并启动我的便携式服务器不是一种选择。 无论如何,由于已经活跃的httpd.exe我的便携式服务器的WordPress站点只能通过localhost访问:81 - 这是一个问题,因为WP站点非常依赖于URL,我不想在WP上包含带端口的url 数据库。

这是我想要做的事情.htaccess:

  • 在除error.php文件检查之外的任何路径上 如果不是端口80
  • 如果不是端口80重定向到/error.php?code=port
nn

它可能是 优先于WP重定向或URL处理?

在error.php中,我提供了有关如何手动关闭httpd.exe的信息,以便我的家人和朋友可以访问便携式站点。 这有点像事件和其他类似东西的画廊和日历应用......

请帮帮忙? 我根本无法解决这个问题。 我知道其他人可能没有apache已经运行,但我想为这种情况做好准备。

如下所示,但以下情况不起作用。

  #BEGIN WordPress 
&lt; IfModule mod_rewrite.c&gt; 
&lt; If“%{SERVER_PORT} = 80”&gt; 
 RewriteEngine On 
 RewriteBase / 
 RewriteRule ^ index \ .php  $  -  [L] 
 RewriteCond%{REQUEST_FILENAME}!-f 
 RewriteCond%{REQUEST_FILENAME}!-d 
 RewriteRule。  /index.php [L] 
&lt; / If&gt; 
&lt; Else&gt; 
 RewriteEngine On 
 RewriteRule ^(error.php)($ | /) -  [L] 
 RewriteRule ^(。*)  $ /error.php?code=port [L] 
&lt; / Else&gt; 
&lt; / IfModule&gt; 
 #END WordPress 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongxuan1660 2012-09-22 16:57
    已采纳
    #  <If "%{SERVER_PORT} = 80">
    RewriteEngine On
    RewriteBase /
    RewriteCond  %{SERVER_PORT} ^80$ 
    RewriteRule ^index\.php$ - [L]
    RewriteCond  %{SERVER_PORT} ^80$ 
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    #</If>
    #<Else>
    RewriteEngine On
    RewriteCond  %{SERVER_PORT} !^80$ 
    RewriteRule ^(error.php)($|/) - [L]
    RewriteCond  %{SERVER_PORT} !^80$ 
    RewriteRule ^(.*)$ /error.php?code=port [L]
    #</Else>
    
    评论
    解决 无用
    打赏 举报
查看更多回答(2条)

相关推荐 更多相似问题