除了重写规则的一些网址
I inserted this rule in my .htaccess
file:
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?content=category&categoryname=$1 [NC,L]
In this way I can get friendly urls like this: http://localhost/mysite/london
I'd also like to use a friendly url for my contact page like so: https://localhost/mysite/index.php?content=message to become: https://localhost/mysite/contact
But if I insert the below rule into .htaccess
...
RewriteRule ^contact/?$ index.php?content=message [NC,L]
...it doesn't work as it seems that the rule for the categories affects this rule.
In fact, if I comment out the category rule...
#RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?content=category&categoryname=$1 [NC,L]
...the url friendly rule for the contact page works (https://localhost/mysite/contact)
So I'm looking for the possibility to exclude some parameter from the category rule to allow for a redirect in some case to another url.
Thanks for any suggestions...
我在 通过这种方式,我可以获得这样的友好网址:
http:// localhost / mysite / london p>
我还想为我的联系页面使用友好的URL,如下所示:
https://localhost/mysite/index.php?content = message 成为:
https:// localhost / mysite / contact p>
但如果我将以下规则插入 ...它不起作用,因为似乎类别的规则会影响此规则。 p>
事实上,如果我 注释掉类别规则...... p>
...联系页面的网址友好规则有效( https:// localhost / mysite / contact ) p>
所以我正在寻找从类别规则中排除某些参数的可能性 允许在某些情况下重定向到另一个网址。 p>
感谢您的任何建议...... p>
div> .htaccess code>文件中插入了这条规则: p>
\ n
RewriteRule ^([A-Za-z0-9 - ] +)/?$ index.php?content = category& categoryname = $ 1 [NC,L]
code> pre >
.htaccess code > ... p>
RewriteRule ^ contact /?$ index.php?content = message [NC,L]
code> pre>
#RewriteRule ^([A-Za-z0-9 - ] +)/?$ index.php?content = category& categoryname = $ 1 [NC,L]
code> pre>
Firstly you need to make sure the contact rule is placed before the more generic one so htaccess can process it first:
RewriteRule ^contact/?$ index.php?content=message [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?content=category&categoryname=$1 [NC,L]
If you have it the other way around the generic rule will always be looked at and match before htaccess even gets to the contact rule.
Note though that the way you wrote your rules it will only match URLs such as
https://exmaple.com/contact
but not
https://exmaple.com/contact/something-else
However, looking at your more generic rule I assume this is intentional.