【问题标题】:How to redirect http requests to another directory by htaccess如何通过 htaccess 将 http 请求重定向到另一个目录
【发布时间】:2020-10-16 17:11:00
【问题描述】:

你们怎么了。

我有一个问题,我想在一个目录下创建一组类似的 php 页面,然后客户端请求它。

这样:

countries/egypt.php
countries/algeria.php
countries/oman.php

and so on.

如果客户端请求https://example.com/egypt apache 服务器调用/var/www/html/countries/egypt.php

当客户端输入https://example.com/oman apache 服务器调用/var/www/html/countries/oman.php

等等。

我的问题在这里如何使用 htaccess 和 apache 服务器?

【问题讨论】:

    标签: php apache .htaccess


    【解决方案1】:

    您可以在站点根目录中使用此 .htaccess:

    RewriteEngine On
    
    ewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT}/countries/$1.php -f
    RewriteRule ^([\w-]+)/?$ countries/$1.php [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-07
      • 2019-11-24
      • 2015-12-02
      • 2011-08-08
      • 2022-01-16
      • 1970-01-01
      相关资源
      最近更新 更多