SEO friendly URLs (.htaccess)

2019-01-20 15:50发布

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

2条回答
欢心
2楼-- · 2019-01-20 16:11

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.

查看更多
一夜七次
3楼-- · 2019-01-20 16:36

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]
查看更多
登录 后发表回答