简体   繁体   English

.htaccess漂亮的URL问题

[英].htaccess Pretty URLS issue

Having a bit of a problem and wondering what I've done wrong. 有点问题,想知道我做错了什么。

Options -Multiviews

RewriteEngine On
RewriteBase /

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.rentus.com/$1 [R=301,L]

RewriteRule ^([a-z]+)\/?$ $1.php [NC]
RewriteRule ^([-a-z]+)\/([-a-z]+)/?$ category.php?param=$1&param2=$2 [L,QSA]
RewriteRule ^([-a-z]+)\/([-a-z]+)/?$ city.php?param=$1&param2=$2 [L,QSA]

So it works with general pages like "/about/" and then category.php with query strings on category.php "/category/hats/". 因此,它适用于“ / about /”之类的常规页面,然后适用于category.php以及category.php“ / category / hats /”上的查询字符串。

When I try to load "/city/losangeles/" Its loading category.php file instead of city.php file. 当我尝试加载“ / city / losangeles /”时,其加载category.php文件而不是city.php文件。 Any idea what I can do to make this work properly and use the php file I tell it too? 任何想法我能做些什么才能使其正常工作并使用我告诉过的php文件吗?

Your rules are the exact same, so it wont ever reach the second: 您的规则完全相同,因此永远不会达到第二个规则:

RewriteRule ^([-a-z]+)\/([-a-z]+)/?$ category.php?param=$1&param2=$2 [L,QSA]
RewriteRule ^([-a-z]+)\/([-a-z]+)/?$ city.php?param=$1&param2=$2 [L,QSA]

Try this (Be aware, your param will no longer contain category/city, and will now include the actual category or city): 尝试以下操作(请注意,您的参数将不再包含类别/城市,现在将包括实际的类别或城市):

RewriteRule ^category\/([-a-z]+)/?$ category.php?param=$1 [L,QSA]
RewriteRule ^city\/([-a-z]+)/?$ city.php?param=$1 [L,QSA]

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

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