Question

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.

Was it helpful?

Solution

I'd recommend going about skinning your application differently. The way you have it now will create duplicate content issues with search engines because they will see the same content for each page on your site for every skin you have.

That is to say, yoursite.com/dark/about.html would be identical content to yoursite.com/spring/about.html so search engines may have a hard time deciding which version to use. In addition, it seems like it will create extra work for linking to other pages on your site since you will have to create your links programmatically to use the proper path and skin.

I would just have a URL for activating a skin and store their preference in a cookie or in a session and skin the site based on the cookie/session value and only maintain one set of URLs.

Unless you really want the skin to be in the URL, I would shy away from using the URL or query string to indicate which skin to use. Instead have it be a preference attached to an account or stored in a cookie.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top