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
  • 写回答

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条)

报告相同问题?

悬赏问题

  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程