使用htaccess从网址中删除子文件夹名称和文件扩展名 [英] removing subfolder name and file extension from url using htaccess

查看:57
本文介绍了使用htaccess从网址中删除子文件夹名称和文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从下面的URL中删除seo/文件夹名称和文件扩展名(.html).我正在一个静态的html网站上.

I want to remove the seo/ folder name and the file extension(.html) from the below url. I am working on a static html website.

www.example.com/seo/advanced-system.html www.example.com/advanced-system/

在我的 root 文件夹的.htaccess中,我已经写了这个文件,

In .htaccess of my root folder I have written this,

RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^seo/(.*)$ www.example.com/$1 [L,R=301]

在我的子文件夹的.htaccess文件中,我已经写过

In .htaccess of my subfolder I have written this,

RewriteRule ^(.*)$ /$1 [R=301,L]

我用Google搜索并尝试了所有可能的方法,但是找不到解决方案.请帮助我.

I googled and tried all possible ways, but not able to find the solution. Please help me.

推荐答案

在我的根文件夹的.htaccess文件中,使用此

In .htaccess of my root folder, use this

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!seo/).*)$ seo/$1 [L,NC]

/seo/的.htaccess中,使用以下命令:

In .htaccess of /seo/, use this:

RewriteEngine On
RewriteBase /seo/

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

这篇关于使用htaccess从网址中删除子文件夹名称和文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆