htaccess Question


J

Jeff Thies

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 mobile.some-site.com all
the links point to www.some-site.com. I'd like to rewrite these to
mobile.some-site.com

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

Jeff
 
Ad

Advertisements

D

Denis McMahon

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 mobile.some-site.com all
the links point to www.some-site.com. I'd like to rewrite these to
mobile.some-site.com

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

If the links in the html files are hard coded in as strings in the text
like "http://www.some-site.com/blah", I don't think .htaccess on it's own
will let you dynamically change the file content to replace that with
"http://mobile.some-site.com/blah", 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:

"http://www.some-site.com/blah"

into:

"http:/blah"

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.
 
Ad

Advertisements

J

Jeff Thies

If the links in the html files are hard coded in as strings in the text
like "http://www.some-site.com/blah", I don't think .htaccess on it's own
will let you dynamically change the file content to replace that with
"http://mobile.some-site.com/blah", 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:

"http://www.some-site.com/blah"

into:

"http:/blah"

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

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} www.X.com [nc]
RewriteRule ^(.*)$ http://mobile.X.com/blog/$1 [R=301,L]
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top