Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex .HTAccess-如何修改文件名中分数不足的url作为子目录?_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Regex .HTAccess-如何修改文件名中分数不足的url作为子目录?

Regex .HTAccess-如何修改文件名中分数不足的url作为子目录?,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,假设我有一个包含以下文件的目录: news_sports.html news_food.html news.html index.html 我该如何使用.Htaccess使其在我的网站被访问时从news_sports.html中获取,从news_food.html中读取,并从news_food.html中读取(无论末尾是否有斜杠) 我当前的.Htaccess文件: RewriteEngine on RewriteCond %{REQUEST_FILENAME} -f [OR] Rewrite

假设我有一个包含以下文件的目录:

news_sports.html
news_food.html
news.html
index.html
我该如何使用.Htaccess使其在我的网站被访问时从news_sports.html中获取,从news_food.html中读取,并从news_food.html中读取(无论末尾是否有斜杠)

我当前的.Htaccess文件:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteCond %{DOCUMENT_ROOT}/$1_$2\.html -f
RewriteRule ^en-gb/([^/]+)/([^/.]+)/?$ $1_$2.html [L,NC]

RewriteCond %{DOCUMENT_ROOT}/$1\.html -f
RewriteRule ^(.+?)/?$ $1.html [L]

RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^en-gb(.*)$ /site/views/en/gb/$1 [L,NC]
目录结构

HTDOCS
  ->site
    ->views
       ->en
         ->gb
            ->index.html
            ->news.html
            ->news_sport.html
            ->news_food.html
         ->us
         ->au
为了总结这一点,我希望这样,当用户使用以下url进入我的站点时:apache需要从HTDOCS->site->views->en->gb->news\u sports.html提供服务


提前感谢

您可以为下划线条件使用新规则:

RewriteEngine on

RewriteRule ^en-gb/([^/]+)/([^/.]+)/?$ /site/views/en/gb/$1_$2.html [L,NC]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteCond %{DOCUMENT_ROOT}/$1\.html -f
RewriteRule ^(.+?)/?$ $1.html [L]

RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule ^en-gb(.*)$ /site/views/en/gb/$1 [L,NC]
让我们。