Forum Moderators: phranque
I'm trying to get the mod rewrite working for my site which use some parameters in the url (I read in this forum that is not very good for the SERPS so I'm trying to improve).
then I defined this in my .htaccess
RewriteEngine on
RewriteRule ^(.+)/(.+) /index.php?men=$1&opt=$2 [R=301,L]
it works fine, but the issue is that I'm using a subdomain (also using AS in my pages) that for some reason when I access thru h*ttp://www.sub.page.com get better AS than when I use sub h*ttp://sub.page.com.
Then I use the h*ttp://www.sub.page.com to load the page the first time .. and I'm dinamically creating a menu with links to pages like dir/page.html which the mod rewrite will redirect to index.php?men=dir&pag=page.html according to the example then with those parameters I'm able to construct the new content .. but when the page is loaded it comes with the form h*ttp://sub.page.com instead of the form h*ttp://www.sub.page.com which is making me cry becuase the page loaded in the way h*ttp://sub.page.com does not work as good as h*ttp://www.sub.page.com for the AS.
Any idead why h*ttp://www.sub.page.com is getting converted to h*ttp://sub.page.com?
Thanks a lot,
CS.
These are issues beyond the code you posted. I'd suggest resolving them first, possibly with help from your hosting company, before complicating matters with additional redirects. The issue with pages not being constructed properly for the alternate subdomain needs to be fixed first - That is a far greater site liability effectiveness-wise than a one-or-two-parameter query string -- If people think your site is broken, they'll leave.
The subdomain redirect is most likely occurring either because of other .htaccess code that you haven't posted, because of settings in the httpd.conf server configurations, or because the AS (whatever that is) is outputting URLs in that form.
Jim
Actually the links were working, the only issue was to getting the page loaded as ht*p://subd.domin.com/index.php?par1=xx&par2=xx instead of (note the www) ht*p://www.subd.domin.com/index.php?par1=xx&par2=xx
But I was able to work around using the full path in the .htaccess , so, my htaccess now lokks like:
RewriteEngine on
RewriteRule ^(.+)/(.+) [subd.domin.com...] [R=301,L]
and AS = Ad Sense by Google (the contextual ads) are working much better now.
Do you know if there is some issue doing the Rewrite like that? using absolute url instead of relative?
Thanks again,
CS.
Yes, actually; It undoes what you are trying to accomplish. This is an external redirect, and as such, tells the search engine coming in using your static (no query-string) URL to drop that static URL and use the query string URL. It also causes the query string URL to appear in the browser address bar. The browser then issues a new HTTP request for the page.
I apologize for not spotting this in your first post. I believe the variant you need for search engine purposes is this:
RewriteEngine on
RewriteRule ^([b][^/][/b]+)/(.+) /index.php?men=$1&opt=$2 [b][L][/b]
However, I'm not sure what the effect will be on the domain-switching problem. I still believe that some agent outside of .htaccess is causing that problem, because you have not mentioned doing any domain-dependent rewrites. I'd take a close look at your script to be sure the links it generates are all specifying the proper (sub)domain name. Also, if you don't have different content on each (sub)domain, then I'd strongly suggest using and advertising only one of them, and redirecting the rest of them to that one; Confusing the mediabot is a sure way to get PSAs instead of relevant ads.
Jim
Thanks a lot for your help... I'm really very new about this stuff .. actually no Linux, no Apache :-( just the basics ;-)
I did the changes you said before, it is redirecting better now, I'm getting the ht*p://www.subdo.domin.com :-) that's good. And in addition the parameters are not being showed in the url :-) what I was looking how to do it also :-)
Now the bad news :-s ... for some reason now, the redirect is like "moving" my root directory one level below, in this example /dir1 would be the new root ... this is:
I have the main url ht*p://www.subd.domin.com , that loads perfect, then I have the links in the page, one of them ie is like this ht*p://www.subd.domin.com/dir1/pag1.html ... which the redirect is traslating to ht*p://www.subd.domin.com/index.php?men=dir1&opt=pag1.html which is perfect (here let's make clear I have not a dir1/pag1.html page, I'm just using the parameters to build the content). Now when I click one of the links to load a different page the firts problem is that I'm lossing the styles.css file reference, meaning that if I see the source code the reference is there but because the root directory was moved now the location for the file would be a level above. And second issue is that the new links are being constructed starting at the new current location, so those looks like ht*p://www.subd.domin.com/dir1/dir1/pag1.html (note the double /dir1/dir1/) result... next click over a link and "Page does not exist" :-( .. I does not happen if I put back the R=301, but then the parameters are back visible in the url and no www.sub either :-(
I was also checking the .htaccess in the main root and I don't see any redirect there, the .htaccess that I'm using is located in the root folder for the subdomain and all what it has is those two lines.
I hope you can help me.
Thanks,
Carlos.
I was able to work around making all the links and the css file relative to the root directory .. like /style.css instead of just style.css for example .. or /dir/pag.htm instead of just dir/pag.htm
Anyway if you know how I can avoid the issue without this work around it would be cool.
Thanks a lot for all yor help.
Carlos.