简体   繁体   English

我想创建一个URL重写以获取最后一个文件夹并将其用作文件

[英]I want create a url rewriting that get last folder and use it as file

The first folder (lang) is fixed and the "output" should be have only last folder with ".php" extension. 第一个文件夹(lang)是固定的,“输出”应该只有最后一个带有“ .php”扩展名的文件夹。

(Is possible to get first folder without create n rule for each language? "/en/blog/") (是否可以在不为每种语言创建n规则的情况下获得第一个文件夹?“ / en / blog /”)

(Is possible add the slash at the end of the url if not present ? "/en/blog" --> "/en/blog/" ) (如果不存在,是否可以在网址末尾添加斜杠?“ / en / blog”->“ / en / blog /”)

Examples: 例子:

From: 从:

/it/blog/

To: 至:

/it/blog.php

From: 从:

/it/blog/notizie/

To: 至:

/it/notizie.php

From: 从:

/it/blog/notizie/file/

To: 至:

/it/file.php

You can use this code in your DOCUMENT_ROOT/.htaccess file: 您可以在DOCUMENT_ROOT/.htaccess文件中使用以下代码:

DirectorySlash On
RewriteEngine On
RewriteBase /

## Add a trailing slash if missing
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s/+(.*?)[^/][?/]?\s
RewriteRule [^/]$ %{REQUEST_URI}/ [L,NE,R=301]

RewriteRule ^/?([a-z]{2})/.*?([^/.]+)/$ $1/$2.php [L,NC]

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

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