dongyu2047 2017-12-18 23:33
浏览 12

用于php api的htaccess

I am trying to configure an htaccess file for the first time. I've searched around and can't figure out what I'm doing wrong. I'm attempting to do the following:

1 - I would like http://localhost/phpinfo to load phpinfo.php (This works) located in /var/www/phpinfo/php

2 - I would like http://localhost/products to load api/product/read.php (located in /var/www/api/product/read.php) but it returns a 404 - The requested URL /products/ was not found on this server

I'm obviously configuring the .htaccess (located in /var/www/.htaccess) file wrong but have got myself completely confused!

.htaccess file

<IfModule mod_rewrite>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/phpinfo/$ phpinfo.php [NC,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/products/$ api/product/read.php [NC,L]

</IfModule>

Apache.config for AllowOverride

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

#<Directory /srv/>
#       Options Indexes FollowSymLinks
#       AllowOverride None
#       Require all granted
#</Directory>

Any ideas or pointing in the right direction would be greatly appreciated :-)

Update taking on board comments (thank you), still no joy :-(

So, now I have modified the .htaccess file as follows. I've moved the phpfile out of the root directory as I thought that might have been giving me a false positive, which it turned out was the case.

<IfModule mod_rewrite>
    Options +FollowSymlinks
    RewriteEngine on

    RewriteCond %{REQUEST_URI} ^/?phpinfo/?$
    RewriteRule ^(.*)$ /api/phpinfo.php [NC,L]

    RewriteCond %{REQUEST_URI} ^/?products/?$
   RewriteRule ^(.*)$ /api/product/read.php [NC,L]
</IfModule> 

Now, neither rewrites are working, I get a 404 for both http://localhost/phpinfo and http://localhost/products.

File structure is now:

/var/www/api/phpinfo.php

/var/www/api/product/read.php (no change from the above but included for reference)

  • 写回答

3条回答 默认 最新

  • dpuwov1487 2017-12-18 23:39
    关注

    Try adding:

    Options +FollowSymLinks
    

    Above:

    RewriteEngine On
    

    In your .htaccess file.

    And delete the

    RewriteCond %{REQUEST_FILENAME} !-d
    

    of the second rule as products exists as a directory and the following rewrite rule will not be applied.

    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测