.htaccess重写每个请求index.php

时间:2017-10-15 03:20:42

标签: php apache .htaccess mod-rewrite url-rewriting

我第一次使用.htaccess而我遇到了循环问题。我试图实现以下目标:

  1. http://something.com重写为http://something.com/main

  2. http://something.com/anything重写为http://something.com/index.php?page=anything

  3. 到目前为止,我目前的尝试看起来像这样,效果令人满意:

    RewriteEngine on
    RewriteBase /
    
    RewriteRule ^/?$ /main [L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    
    RewriteRule ^(.*)$ /index.php?page=$1 [NC,L]
    

    但是,我想删除这两个重写条件,以便允许http://something.com/index.php的请求变为http://something.com/index.php?page=index.php。删除两个RewriteCond行会导致循环,并且重写不起作用。

    我做错了什么,如何解决问题?谢谢!

1 个答案:

答案 0 :(得分:1)

您可以删除这些条件,但是您需要撤消规则并从目标URI中删除前导// source used: __m128i vec = _mm_setr_epi8(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); // output: v2_u64: 0x807060504030201 0x100f0e0d0c0b0a09 v4_u32: 0x4030201 0x8070605 0xc0b0a09 0x100f0e0d v8_u16: 0x201 0x403 0x605 0x807 | 0xa09 0xc0b 0xe0d 0x100f v16_u8: 0x1 0x2 0x3 0x4 | 0x5 0x6 0x7 0x8 | 0x9 0xa 0xb 0xc | 0xd 0xe 0xf 0x10

/

另请记住,现在您的第一条规则也会将css / js / image请求重写为RewriteEngine on RewriteBase / RewriteRule ^(.+)$ index.php?page=$1 [QSA,L] RewriteRule ^/?$ main [L] 。如果您想避免这种情况,请在第一个index.php?page=...之前添加此条件:

RewriteRule