0

I have a url as below.

http://example.com/listing?listingid=237508&2000

What I want is to redirect it to a mobile version of the site.

http://example.com/mobile-listing?listingid=237508&2000

The problem is that if it is example.com/listing it should redirect to example.com/mobile-listing. If it is example.com/event it should redirect to example.com/mobile-event and so on. How am I to do this? I have seen question about redirection to mobile version based on url parameters or getvalue. But not this way. Any help would be greatly appreciated. Thanks.

3 Answers 3

1

i've found a simuluar answer from ulrich palha which might helps. question id 9113747 in the .htaccess file of root you can try this:

RewriteEngine on
RewriteBase /

RewriteCond %{QUERY_STRING} (^|&)listingid= [NC] 
RewriteRule ^ mobile-listing [L,R=301]

hopes this helps. you might change a little and this should point in the right direction to the solution.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to use a RewriteRule directive and QSA and PT flags

<VirtualHost *:80>
    RewriteEngine on
    RewriteRule ^/listing$ /mobile-listing [PT,QSA] 
    …
</VirtualHost>

Flags

Forces the resulting URI to be passed back to the URL mapping engine for processing of other URI-to-filename translators, such as Alias or Redirect. details ...

Appends any query string from the original request URL to any query string created in the rewrite target.details

More information

You can find more scenarios at Redirecting and Remapping with mod_rewrite.

Comments

0

Without any sort of condition for what is mobile or what isn't, and you always redirect, then the rule would look something like this:

RewriteCond %{REQUEST_URI} !^/mobile-
RewriteRule ^([^/]+)$ /mobile-$1 [L,R]

The query string will automatically get appended. Change the R to R=301 if you want to permanently redirect.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.