2017-08-14 71 views
0

下面是我的.htaccess代碼:阿帕奇重寫規則無法正常運行

<VirtualHost *:80> 
     ServerName api.xxxx.com 
     DocumentRoot /dianxiaoer/html/two-twenty 
     <Directory /dianxiaoer/html/two-twenty> 
       RewriteEngine on 
       RewriteCond %{REQUEST_FILENAME} !-f 
       RewriteCond %{REQUEST_FILENAME} !-d 
       RewriteRule . index.php 
       RewriteRule /notify/alipay /mobile/index.php?act=notify&op=alipay 
       #Options Indexes FollowSymLinks MultiViews 
       Options FollowSymLinks 
       AllowOverride None 
       Require all granted 
       Order allow,deny 
       allow from all 
     </Directory> 
</VirtualHost> 

URL重寫規則

api.xxxx.com/notify/alipay to api.xxxx.com/mobile/index.php?act=notify&op=alipay 

無法正常工作。任何人都可以請解釋我在這裏做錯了什麼?謝謝。

+1

你有什麼錯誤? – CUGreen

+0

代碼的第九行不起作用,無法重定向 – uzaiHu

+0

可能是因爲第8行的規則覆蓋了它 – CUGreen

回答

0

此行RewriteRule . index.php將覆蓋它後面的任何內容。

如果你把那個放在最後,它應該解決你的問題。

試換8號線和9這樣的:

<VirtualHost *:80> 
     ServerName api.xxxx.com 
     DocumentRoot /dianxiaoer/html/two-twenty 
     <Directory /dianxiaoer/html/two-twenty> 
       RewriteEngine on 
       RewriteCond %{REQUEST_FILENAME} !-f 
       RewriteCond %{REQUEST_FILENAME} !-d 
       RewriteRule /notify/alipay /mobile/index.php?act=notify&op=alipay [L] 
       RewriteRule . index.php 
       #Options Indexes FollowSymLinks MultiViews 
       Options FollowSymLinks 
       AllowOverride None 
       Require all granted 
       Order allow,deny 
       allow from all 
     </Directory> 
</VirtualHost> 

希望可以解決您的問題。