简体   繁体   English

SEO友好URL(.htaccess)

[英]SEO friendly URLs (.htaccess)

http://www.domain.com/folder/file?x=1&y=2

Change to: 改成:

http://www.domain.com/folder/file/1/2/

http://www.domain.com/folder/?x=1

Change to: 改成:

http://www.domain.com/folder/1/

I tried: 我试过了:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^folder/(.*)/$ folder/index.php?x=$1 [L]
RewriteRule ^folder/file/(.*)/(.*)/$ folder/file.php?x=$1&y=$2 [L]

but that doesn't work, does anyone have any idea why? 但这行不通,有人知道为什么吗?

when i take out the first rule, i can access the second one via: 当我删除第一条规则时,我可以通过以下方式访问第二条规则:

http://www.domain.com/folder/1/2/

but not: 但不是:

http://www.domain.com/folder/file/1/2/

god, i hope i am not confusing anyone who is reading this lol i hope it makes sense 天哪,我希望我不会混淆正在阅读此笑的任何人,我希望这是有道理的

Try 尝试

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^folder/file/(.*)/(.*)/ /folder/file.php?x=$1&y=$2 [L]
RewriteRule ^folder/(.*)/ /folder/index.php?x=$1 [L]

The order of the rules is important. 规则的顺序很重要。 You should always put the one with the most rules first as your way was getting to the first rule and then stopping because it was always true due to the (.*) which was capturing the file . 当您到达第一个规则时,应该始终将规则最多的规则放在第一位,然后停止,因为由于(.*)正在捕获file所以它始终为真。

Did you try adding a / before the folder name? 您是否尝试在文件夹名称前添加/?

RewriteRule ^folder/(.*)/$ /folder/index.php?x=$1 [L]
RewriteRule ^folder/file/(.*)/(.*)/$ /folder/file.php?x=$1&y=$2 [L]

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

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