.htaccess中的多个连字符处理(URL重写) [英] Multiple hyphen handling in .htaccess (URL rewriting)

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

问题描述

我对URL重写有疑问。我在.htaccess文件中写了以下规则

  RewriteRule ^ c-([^ /] *)-([^ /] *)/ $ cat.php?id = $ 1& slug = $ 2 

这样的网址: http:// localhost / actuco / c-628Y8x-france / (包含类别ID及其子类别)。此URL完美地工作。



但是,当我键入此URL时: http:// localhost / actuco / c-xpS3cc-amerique-du-nord /
它不再起作用。问题的原因必须是这样的事实:后一个条块包含多个连字符(amerique-du-nord),而第一个条(france)根本不包含连字符(我尝试了所有带有多个连字符的块的类别)。 / p>

有人知道如何解决这个问题吗?



这是我完整的.htaccess代码

 选项+关注符号链接

RewriteEngine On

RewriteBase / actuco /
#RewriteCond %{REQUEST_FILENAME}!-f
#RewriteCond%{REQUEST_URI} /+[^\.]+$
#RewriteRule ^(。+ [^ /])$%{REQUEST_URI} / [R = 301,L]
RewriteRule ^([^ /] *)/([^ /] *)/([^ /] *)/([^ /] *)/([^ /] *) /([^ /] *)/ $ article.php?lng = $ 1& yr = $ 2& mo = $ 3& dy = $ 4& slug = $ 5&total_slug = $ 6
#RewriteRule ^( [^ /] *)-([^ /] *)-([^ /] *)$ waluty.php?cur = $ 1& amt = $ 2& lang = $ 3
RewriteRule ^ c-([ ^ /] *)-([^ /] *)/ $ cat.php?id = $ 1& slug = $ 2
RewriteRule ^([^ /] *)/([^ /] *)/ $ url.php?mode = $ 1& u = $ 2
RewriteRule ^ bio $ o.php [L]

预先感谢!

解决方案

您可以尝试:

  RewriteRule ^ c\-([\w] +)\-([ \w-] +)\ / $ cat.php?id = $ 1& slug = $ 2 


I have a problem with URL rewriting. I have written the following rule in my .htaccess file

RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2

It gives me URLs like that : http://localhost/actuco/c-628Y8x-france/ (featuring the ID of the category, and its slug). This URL works perfectly.

But, when I type this URL : http://localhost/actuco/c-xpS3cc-amerique-du-nord/ it doesn't works anymore. The cause of the problem must be the fact that the latter slug contains several hyphens (amerique-du-nord) whereas the first one (france) contains no hyphens at all (I tried with all my categories with slugs including multiple hyphens).

Does anyone know how to solve this please ?

Here is my complete .htaccess code

Options +FollowSymlinks

RewriteEngine On

RewriteBase /actuco/
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_URI} /+[^\.]+$
#RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ article.php?lng=$1&yr=$2&mo=$3&dy=$4&slug=$5&total_slug=$6
#RewriteRule ^([^/]*)-([^/]*)-([^/]*)$ waluty.php?cur=$1&amt=$2&lang=$3
RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2
RewriteRule ^([^/]*)/([^/]*)/$ url.php?mode=$1&u=$2
RewriteRule ^bio$ o.php [L]

Thanks in advance !

解决方案

You can try:

RewriteRule ^c\-([\w]+)\-([\w-]+)\/$ cat.php?id=$1&slug=$2

这篇关于.htaccess中的多个连字符处理(URL重写)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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