Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>At the end, you have two <code>RewriteRule</code> lines which I believe should be changed to:</p> <pre><code>RewriteRule ^\/?$ http://m.domain.com [R=302] RewriteRule ^\/?(.*)\/?$ http://m.domain.com/$1.html [R=302,L] </code></pre> <p>The <code>^\/?(.*)\/?$</code> means give me a string that starts at the beginning (<strong>^</strong>) and gives me all characters (<strong>(.*)</strong>) until the end (<strong>$</strong>) without the trailing/beginning (<strong>/</strong>) if there is one (<strong>?</strong>).</p> <p>The <code>http://m.domain.com/$1.html</code> means that if the address is <code>http://www.domain.com/internal-page/</code> then it becomes <code>http://m.domain.com/internal-page.html</code>.</p> <p>The <code>[R=302,L]</code> should mean a 302 redirect (<strong>R=302</strong>) and the last rewrite (<strong>L</strong>), so no other rewrites can occur on our URL.</p> <p><strong>EDIT:</strong></p> <p>I believe that in the case of your <em>RewriteRules</em> the first one was redirecting to <code>http://m.domain.com</code> in the event that the URL was just the domain, but if there was anything else then the second rewrite was failing because it was not actually literally <code>/internal-page/</code> and you needed a regex variable to put into the new URL.</p> <p><strong>EDIT (2):</strong></p> <p>To redirect to each mobile page from a specific desktop page:</p> <pre><code>RewriteRule ^\/foo\/?$ http://m.domain.com/bar.html [R=302] RewriteRule ^\/hello\/?$ http://m.domain.com/world.html [R=302] </code></pre> <p>The (<strong>/?</strong>) means that a <strong>/</strong> is optional in that position and the (<strong>^</strong>) denotes beginning and (<strong>$</strong>) denotes ending in this case (the <strong>^</strong> can also be used to indicated something like <code>[^\.]</code> which means anything <em><strong>except</strong></em> a period).</p> <p>Just put how ever many of those that you need in a row to do the redirecting and that should do the trick. To make sure there are no misconceptions, the first line would mean that <code>http://www.domain.com/foo/</code> would become <code>http://m.domain.com/bar.html</code> and because the trailing slash is made optional <code>http://www.domain.com/foo</code> (notice the trailing forward slash is absent) would also redirect to <code>http://m.domain.com/bar.html</code>.</p> <p>You can play with the syntax a bit to customize it, but hopefully I've pointed you in the right direction. If you need anything else, let me know, I'll do my best to assist.</p> <p>I don't want to sound like a broken record or anything, but I feel that I could not, in good conscience, end this edit without pointing out that modifying the mobile site would be a much better way to do this. If it is not possible or you feel that a few static redirects are not a big deal versus modifying some pages, then I totally understand, but here are a few things for you to think about:</p> <p>If the mobile site and desktop site are in separate folders then the exact same name scheme can be used for both making the Rewrites simpler and meaning that as new pages/content are added you will not need more Rewrite statements (making more rewrites means you have to create the new pages and then you have to create the redirects. that's extra work and more files which require your attention.)</p> <p>If the mobile site is actually hosted from the same directory as the desktop site, then changing the files for one or the other so it becomes something like <code>/desktop-foo/</code> or <code>/d-foo/</code> then it is very easy to make the rewrite (redirect) go to something like <code>/m-foo.html</code>. You could forego modifying the desktop pages and make <code>/foo/</code> become <code>/m-foo.html</code> and make all your mobile versions begin with an 'm'.</p> <p>The third option that comes to mind is the most difficult and time consuming, depending on the content of the site, but it is a pretty cool one and ultimately would make the site the easiest to work on (after the initial work, of course). It is quite possible to use the same page for desktop, mobile, tablet, etc without the use of mod_rewrite or separate pages. Things like media queries in your CSS would allow you to change the look of the page depending on what the client is viewing it from. I came across a tutorial on the subject earlier which used media queries and the max-width of the screen to determine how the page should look. This would require a good bit of work now, but could save some hassle down the road as well as being an interesting learning experience if you are up to the challenge.</p> <p>Again, sorry that this veered off topic at the end there, but I got the impression from your original question and your responses that you might find the alternatives interesting if you haven't already considered and dismissed them and that even if the alternatives do not interest you that you aren't going to be like some people and respond with, "Hey, $*%&amp; you, buddy! I asked for Rewrites not all that other garbage!" I hope you take it as nothing more than what it is intended to be...helpful.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload