Forum Moderators: phranque
where $cat is a number from 0 to any value.
I rewrite the URL using the following code at .htaccess,
RewriteEngine on
RewriteBase /
RewriteRule ^phil(.*).htm index.php?cat=$1 [L]
RewriteRule ^addurl(.*).htm index.php?action=reclink&cat=$1 [L]
my pages will now have the following URL,
[mydomain.com...]
[mydomain.com...]
My problem is that, in the recent index of google, google indexed my pages as it was not "rewrited". What i mean is that, instead of having,
[mydomain.com...]
[mydomain.com...]
google index it as,
[mydomain.com...]
[mydomain.com...]
I have noticed it in my cpanel.
Question:
Is there a problem with google or in my code?
Thanks.
[edited by: jdMorgan at 4:29 pm (utc) on May 4, 2005]
[edit reason] Removed specifics per TOS. [/edit]
The problem is you're going the wrong way, and maybe a couple of other minor things...
Start here:
[webmasterworld.com...]
If you still have questions, post again.
Justin
BTW if you can still get in you should remove the URL for your site... 'TOS'
RewriteEngine on
RewriteBase /dir/
RewriteRule ^phil(.*).htm index.php?cat=$1 [L]
RewriteRule ^addurl(.*).htm index.php?action=reclink&cat=$1 [L]
to produce these;
[mydomain.com...]
[mydomain.com...]
from these;
[mydomain.com...]
[mydomain.com...]
sorry for posting my website, I though it would help you analyze my problem. how can i delete it?
It sounds as though you are wanting Apache to change the URL displayed in the browser, but display the information from the originally requested page...
If this is the case, the problem is not the .htaccess code per se, but rather the links on your page. For a silent redirect to happen, the URL you would like to have displayed must be requested... EG some one must click on a link to, type in, or first be externally redirected to the URL you are internally or 'silently' redirecting. If none of these has happened the neither the URL, nor the information will be served in the way you would like.
If this is not the case, please post again, with (generalized) detailed information about your linking structure and any (generalized) specifics on how your .htaccess and site navigation is set up.
Hope this helps.
Justin
first, i have a website with the following URL patern for all pages:
(1) www.domain.com/dir/index.php?cat=4
I use mod rewrite so that if i requested,
(2) www.domain.com/phil4.htm
(note: 4 can be any number)
the browser will display, URL (1),
There is no problem on how URL (2) is requested in all my pages. Actually, i havent encounter any problem before. That is, google and other SE crawl my pages as (2). It was only yesterday that i`ve notice that even if all of my pages are linked as (2), the log on my cpanel shows that google sees my pages as (1) even if it is linked as (2). In the first place, there is no page that linked to other pages with pattern No. 1.
Then, the possible problem, i thought is, there is a problem in my code at .htaccess AND/OR google sees the original URL and index it as the pattern (1) even if the URL is requested as in pattern (2). I dont have any problem with other SE, with google only.
Welcome to WebmasterWorld!
You'll need to add more rules that perform the opposite function to those that you already have, and generate a 301 permanent redirect -- but only for external client requests for the dynamic URLs. Example:
# Existing rewrite
RewriteRule ^phil(.*)\.htm$ /index.php?cat=$1 [L]
# New external redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index\.php\?cat=([0-9]+)\ HTTP/
RewriteRule ^index\.php$ /phil%1.htm [R=301,L]
GET /index.php?cat=4 HTTP/1.1
Note also the corrections to your original rule (added literal character escaping and end-anchoring).
Jim
You have a link on your page to www.example.com/phil4.htm
Somebody clicks that link, so their browser requests www.example.com/phil4.htm from your server.
You use mod_rewrite to convert (internally rewrite) that to a call to your script, using the path /dir/index.php?cat=4
So, the correct content is delivered as if it came from a static page at www.example.com/phil4.htm
However, in the past, you used to have direct links such as www.example.com/dir/index.php?cat=4 on your pages, so these URLs have been listed in the search results, and now you want to get rid of them.
So, a search engine requests www.example.com/dir/index.php?cat=4 from your server.
The new rule redirects this request using a 301-Moved Permanently redirect to www.example.com/phil4.htm
So, the search engine re-requests the page from www.example.com/phil4.htm
Then the sequence shown for the user clicking on a static link is executed as above.
The result is that the search engine sees a 301 redirect, which tells it to update the URL it is using -- from your old dynamic link to the new static link.
Jim
(www.mydomain.kom/dir/index.php?cat=143).
what shoud be the exact code to make it,
(www.mydomain.kom/phil143.htm)
note: 143 can be any number
without having any problem again.
Thanks in advance.
Sorry I misunderstood your original question.
You should simply need to add the /dir/ to the path in the rewrite condition (and most likely the rule), like this:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /dir/index\.php\?cat=([0-9]+)\ HTTP/
This is how your entire file would look after making this change:
# Existing rewrite
RewriteRule ^phil(.*)\.htm$ /index.php?cat=$1 [L]
# New external redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /dir/index\.php\?cat=([0-9]+)\ HTTP/
RewriteRule ^dir/index\.php$ /phil%1.htm [R=301,L]
If your .htaccess file is in the root directory, you will need the full path dir/index\.php as is in the rule now. If your .htaccess file is in the directory /dir/ you will need to remover the preceding dir/ from the rule.
Something to note in looking at your original request.
This rewrite will only work for phil$cat, *not* for addurl, or any other requested URL, because every request that ends in?cat=something, will be written to phil$cat.html, and there is no condition that can account for a request that ends in?action=reclink&cat=$cat. You can make adjustments to this either through the use of regular expressions, or unique individual conditions... which is better will depend on your specific situation.
Hope this helps.
Justin
* Please, note I do not see the reason for the server error... the condition not being exact *should* have caused it to fail, but not generate a server error. If you still have the server error after making the adjustment, please continue posting.
Added: You may also need to prepend the original rewrite rule with dir/ on the right side. I am assuming you will not, but I do not know your exact structure, so I cannot say for certain... Obviously if it works now, don't make any changes.
If I am understanding correctly (this is not something I use) the syntax for the base should be /dir not /dir/.
I also believe the rewrite condition must contain the / prior to dir (or index).
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /dir/index\.php\?cat=([0-9]+)\ HTTP/
This [A-Z]{3,9} matches any capital letter from A to Z where there are 3 to 9 letters in a string. It is used to match the from of the request. EG GET, POST, etc.
As far as the error goes, I am just trying to give you some ideas... Either Jim or sitz can give you more detailed information, because RewriteBase is *not* something I use.
Hope this helps.
Justin
No more internal server error when i remove, (^[A-Z]{3,9}) in
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /dir/index\.php\?cat=([0-9]+)\ HTTP/
however, instead of having
(www.domain.kom/phil4.htm)
from
(www.domain.kom/dir/index.php?cat=4),
I got,
(www.domain.kom/phil4.htm?cat=4)
it seems that it only overwrites the first few terms.
# Existing rewrite
RewriteRule ^phil(.*)\.htm$ /index.php?cat=$1 [L]
# New external redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,[b]9}\[/b] /dir/index\.php\?cat=([0-9]+)\ HTTP/
RewriteRule ^dir/index\.php$ /phil%1.htm [R=301,L]
Jim
instead of having
(www.domain.kom/phil4.htm)
from
(www.domain.kom/dir/index.php?cat=4),
I got,
(www.domain.kom/phil4.htm?cat=4)
it seems that it only overwrites the first few terms.
It justs replace /dir/index.php with phil4.htm.
what i want is replace dir/index.php?cat=4 with
phil4.htm.
Thanks for the help guys.
# Existing rewrite
RewriteRule ^phil(.*)\.htm$ /index.php?cat=$1 [L]
# New external redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /dir/index\.php\?cat=([0-9]+)\ HTTP/
RewriteRule ^dir/index\.php$ /phil%1.ht[b]m?[/b] [R=301,L]
Jim