简体   繁体   English

如何通过htaccess将http请求重定向到另一个目录

[英]How to redirect http requests to another directory by htaccess

Whats up guys.怎么了伙计们。

I have a problem that I want to create group of similar php pages under one directory and client request it.我有一个问题,我想在一个目录下创建一组类似的 php 页面并且客户端请求它。

like that:像那样:

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

and so on.

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

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

and so on.等等。

my question here how to it with htaccess and apache server ?我的问题是如何使用 htaccess 和 apache 服务器?

You may use this .htaccess in your site root:您可以在站点根目录中使用此 .htaccess:

RewriteEngine On

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM