我正在尝试在我的应用程序中建立良好的链接。
我决定重写如下所示的链接:
1. http://example.cz/get1/get2/get3
2. http://example.cz
进入这些(我只有php应用程序):
1. http://example.cz/index.php?path=get1+get2+get3
2. http://example.cz/index.php?path=
我在链接之前删除 www。
我一直无法将其重写为.htaccess
.
如果将 get params 重写为 path=get1+get2+get3 的主要想法是好的,我也在寻找建议?现在我可以看到这样的链接http://www.example.cz/you+me/
可能会在某个地方失败。你有更好的解决方案吗?
所以问题是:如何将其重写为 .htaccess 以及如何解决包含“+”的链接可能出现的问题
编辑:
我稍微提高了我的技能,我做到了:
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule (.*) http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^\/index.php(.*)
RewriteRule ^(.+) /index.php?path=/$1 [R=301,L] # 301 is here so I can see how does it work
# everything above works well (as I want)
# link now look like this one:
# http://example.net/index.php?path=/get1/get2/get3
# Now I was looking for universal rule that will rewrite my get params...
# First I did this:
RewriteCond %{REQUEST_URI} /([^/]+)
RewriteCond %1 !index.php(.*)
RewriteRule /([^/]+) $1+ [R=301,L]
# If any part of request uri is string that matches pattern /([^/]+)
# And if ([^/]+) doesn't match index.php(.*)
# then rewrite every /([^/]+) into $1+
# Now I see that it is incorrect, but I wasn't able to fix it
# So then I did different rule
RewriteRule ^([^=]+=[^\/]*)\/([^\/]+)(.*)$ $1$2+$3 [R=301,L]
# start of string
# first var is: one or more chars except =, =, zero or more chars except /
# /
# second var is: one or more chars except /
# third var is: zero or more chars
# end of string
我认为第二个想法要好得多,但它也不起作用。请帮我修复它。