0

アプリで素敵なリンクを作成しようとしています。

次のようなリンクを書き直すことにしました。

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

2番目のアイデアの方がはるかに優れていたと思いますが、うまくいきません。修正するのを手伝ってください。

4

2 に答える 2

0

解決しました。問題は、 index.php?path= を追加した後、クエリ文字列を操作できなかったことです...

http://www.example.net/get1/get2/get3リンクを からに 変える最終的なユニバーサル ソリューションhttp://example.net/index.php?path=get1+get2+get3:

RewriteEngine on
RewriteBase /
Options +FollowSymlinks

RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule (.*) http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_URI} !^\/index.php(.*)
RewriteRule ^(.+) /index.phppath=/$1 [R=301,L]

RewriteRule ^([^=]+=[^/]*)/([^/]+)(.*)$ $1$2+/$3 [R=301,L]
RewriteRule ^(.*)\+/+$ $1 [R=301,L]
RewriteRule ^(.*)path=(.*)$ $1?path=$2 [R=301,L]
于 2013-07-04T11:36:58.383 に答える