htaccess Question

Discussion in 'HTML' started by Jeff Thies, Mar 20, 2014.

  1. Jeff Thies

    Jeff Thies Guest

    I have a Wordpress blog on a site that has hardcoded links with the
    complete url.

    I have replicated this onto a mobile subdomain.

    The problem is that when reading the blog from all
    the links point to I'd like to rewrite these to

    I can't quite wrap my mind around how to do this. I haven't been able to
    do it with HTTP_HOST.

    Jeff Thies, Mar 20, 2014
    1. Advertisements

  2. If the links in the html files are hard coded in as strings in the text
    like "", I don't think .htaccess on it's own
    will let you dynamically change the file content to replace that with
    "", but that might be a lack of my
    knowledge of what .htaccess can do.

    What you could do is edit all the links to change:




    and then depending on whether the pages are on the www.x or mobile.x
    site, they'll pick up the relevant links.

    You might be able to redirect all requests processed by www.x that were
    referred from mobile.x back to mobile.x by using something similar to the
    following in .htaccess in the root of www.x

    RewriteCond %{HTTP_REFERRER} mobile.x
    RewriteRule ^(.*) http://mobile.x/$1

    But this will mean that any intentional link from the mobile site to the
    main site will be redirected as well.
    Denis McMahon, Mar 20, 2014
    1. Advertisements

  3. Jeff Thies

    Jeff Thies Guest

    Thanks. I had some trouble working this out as the mobile blog is a
    symbolic link and there were multiple htaccess files to boot. This works:

    RewriteCond %{HTTP_REFERER} mobile\.X\.com/blog [NC]
    rewritecond %{http_host} [nc]
    RewriteRule ^(.*)$$1 [R=301,L]
    Jeff Thies, Mar 22, 2014
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.