2

I'm doing my first steps with url-rewriting and can't get the following to work:

In my application, a skin can be loaded by applying query parameter ?skin=some_id to any page in the application. I want to change:

 http://www.mysite.com/anypage.html?skin=123

into:

 http://www.mysite.com/123/anypage.html

but I cannot get it to work.

This is what I currently have in my httpd.conf:

<IfModule mod_rewrite.c>
    RRewriteRule (.*)/(.*)?app=(.*)$ %1/%3/%2 [NC,R=301,L]
</IfModule>

Questions:
This isn't working, so I would like to know what I'm doing wrong?

Also with the URL in effect, what is the URL the user enters? http://www.mysite.com/123/anypage.html which "maps" to http://www.mysite.com/anypage.html?skin=123?

And if I want to access the query parameter, do I have to extract it from the actual url (?skin=...) or from the rewritten URL?

Thanks for helping out!

EDIT:
So I have it sort of working doing it like this (helpful tester here):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} skin=(\w+)
RewriteRule ^.*\.html /%1? [R=301]
</IfModule>

This will redirect:

 www.some.com/index.html?skin=xyz   =>  www.some.com/xyz

Not quite there yet.

4

1 回答 1

1

我建议以不同的方式对您的应用程序进行皮肤处理。您现在拥有它的方式将与搜索引擎产生重复的内容问题,因为他们会在您的网站上为您拥有的每种皮肤的每个页面看到相同的内容。

也就是说,yoursite.com/dark/about.html内容相同,yoursite.com/spring/about.html因此搜索引擎可能很难决定使用哪个版本。此外,它似乎会为链接到您网站上的其他页面创建额外的工作,因为您必须以编程方式创建链接以使用正确的路径和皮肤。

我只需要一个用于激活皮肤的 URL,并将他们的偏好存储在 cookie 或会话中,然后根据 cookie/会话值对站点进行皮肤设置,并且只维护一组 URL。

除非您真的希望皮肤位于 URL 中,否则我会回避使用 URL 或查询字符串来指示要使用的皮肤。而是将其作为附加到帐户或存储在 cookie 中的首选项。

于 2013-05-10T00:25:17.383 回答