多斜线的htaccess重写URL [英] htaccess rewriting URLs with multiple forward slashes

查看:126
本文介绍了多斜线的htaccess重写URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图找出一套的.htaccess mod_rewrite的规则,将设置这些链接:

Trying to work out a set of .htaccess mod_rewrite rules that will set these links:

domain.com/content-page
domain.com/region/another-page
domain.com/region/brand/more-content-here

来获取文件:

domain.com/content-page.php
domain.com/region-another-page.php
domain.com/region-brand-more-content-here.php

在哪里'区'和'品牌'和页面名称都是可变/多变。

Where 'region' and 'brand' and the page name are all variable/changeable.

到目前为止,我有:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,C]
RewriteRule ([^/]+)/([^/]+) $1-$2 [NC,L] 

这工作,但只为一个正斜杠。如上所述,域后,网址可能没有,有一个或两个斜杠。没有任何运气试图延长这一处理多个(或没有)斜杠。

This works but only for one forward slash. As mentioned above, URLs after the domain may have none, one or two forward slashes. Haven't had any luck trying to extend this to deal with multiple (or not) slashes.

推荐答案

尝试:

RewriteEngine On

# pass through root
RewriteRUle ^(index\.php)?$ - [L]

# no more / so add extension
RewriteCond $1 !/
RewriteCond $1 !\.php$
RewriteCond ${REQUEST_FILEAME} !-f
RewriteRule ^(.*)$ /$1.php [L]

RewriteCond %{REQUEST_URI} !\.php$
RewriteRule ^(.*)/(.*)$ /$1-$2 [L]

这篇关于多斜线的htaccess重写URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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