Forum Moderators: phranque

Message Too Old, No Replies

Rewrite URLs with certain string

         

guum

8:39 pm on Jul 21, 2010 (gmt 0)

10+ Year Member



Hello. I have a question:
How to rewrite these URLs:

www.example.com/......../?tag=...........

to:

www.example.com/sitemap.html

Thanks

g1smd

8:47 pm on Jul 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you actually mean:

"How to rewrite this URL request:
www.example.com/sitemap.html


to this internal filepath:
/index.php?tag=sitemap
"

or similar?

guum

9:01 am on Jul 22, 2010 (gmt 0)

10+ Year Member



Hello g1smd.
No, I mean:

www.example.com/cad-directory/?tag=autocad
www.example.com/cad-directory/?tag=catia
……………
to
www.example.com/sitemap.html

If a URL has this string "?tag=" always to sitemap.

I want to destroy these links, but not:

www.example.com/cad-directory/...............

I tried this with robots.txt:

Disallow /cad-directory/?tag

But yesterday Googles WebmasterTolls showed indexed pages 0.
The indexed pages:

www.example.com/cad-directory/.................
are still here, but for sure I removed robots.txt entry and I try now with with htaccess.


You remember? My last question about:
(.htaccess conditional redirect domain to subdomain
on multi-language site with shared root folder)
the right solutions was:
######################################

### 1

RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteCond %{REQUEST_URI} ^/cad-uebersicht.html
RewriteRule ^(.*)$ http:://de.example.com/cad-uebersicht.html [R=301,L]

RewriteCond %{HTTP_HOST} ^de\.example\.com
RewriteCond %{REQUEST_URI} ^/cad-overview.html
RewriteRule ^(.*)$ http:://www.example.com/cad-overview.html [R=301,L]

...............

### 2

RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteCond %{REQUEST_URI} ^/cad-verzeichnis/
RewriteRule ^(.*)$ http:://de.example.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^de\.example\.com
RewriteCond %{REQUEST_URI} ^/cad-directory/
RewriteRule ^(.*)$ http:://www.example.com/$1 [R=301,L]

######################################

Maybe you can adapt the answer to my specific environment…

Thank
(webmasterworld is the professional resource ever, nowhere I found such quality like here…)

jdMorgan

5:43 pm on Jul 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could use:

RewriteCond %{QUERY_STRING} ^tag=[^&]+
RewriteRule ^cad-directory/$ http://www.example.com/sitemap.html [R=301,L]

However, it would be far better to instead return a 410-Gone response, and then include a link to the sitemap (and to your home page, major category pages, site search, etc.) on your custom 410-Gone error page, along with a short but clear explanation that the requested resource has been removed.

This is much 'friendlier' to your users (because they get an explanation of what happened to the link that they clicked on) and also looks much better to search engines, which may otherwise see the infinite URL-plus-query-string-space as spammy doorway pages.

ErrorDocument 410 /local-path-to-my-410-gone-error-page.html
#
RewriteCond %{QUERY_STRING} ^tag=[^&]+
RewriteRule ^cad-directory/$ - [G]

Jim

guum

6:41 pm on Aug 9, 2010 (gmt 0)

10+ Year Member



Thank you djMorgen

I had not heard before about 410... I like this solution.

This works for me. For my special environment:
(.htaccess conditional redirect domain to subdomain
on multi-language site with shared root folder)
.............
ErrorDocument 410 /410.html

RewriteCond %{HTTP_HOST} ^www\.exxample\.com
RewriteCond %{QUERY_STRING} ^tag=[^&]+
RewriteRule ^cad-directory/$ http:://www.example.com/ 410.html [G]

RewriteCond %{HTTP_HOST} ^de\.example \.com
RewriteCond %{QUERY_STRING} ^tag=[^&]+
RewriteRule ^cad-verzeichnis/$ [de.cadenigma.com...] 410.html [G]
..............
EFFECT:
http://www.example.com/cad-directory/?tag=autocad
http://www.example.com/cad-directory/?tag=catia
................
redirect to ErrorDocument: 410.html

---------------------------------------------
additional I redirect some Links simple, and this works too:

Redirect gone /events/month/2011-02-01.html
Redirect gone /events/month/2010-06-01.html
...........

EFFECT is like above:
redirect to ErrorDocument: 410.html


Konstantin

jdMorgan

4:07 am on Aug 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do not redirect to the 410 document, just serve it with the 410 response. The correct syntax ia
 RewriteRule ^cad-directory/$ - [G] 


Do not use both "RewriteRule" and "Redirect" in the same server unless you control the server and can specify the Apache module execution order.

Be careful to get this right. If your server returns a redirect, you may destroy your search engine rankings. A 403, 404, or 410 response is NOT a redirect, and the URL in the browser must not change.

Jim

guum

7:00 pm on Aug 10, 2010 (gmt 0)

10+ Year Member



Thank you, Thank you djMorgen

You and G1smd have always said to me: don't redirect...
Now I understand why! I have no more redirect in my htaccess file.

the URL in the browser must not change

Yes, the URL in the Browser remain the same. If I don't define my custom 401.html:
ErrorDocument 410 /410.html
I see a standard page. OK, I have commented out my custom page.

This works for me (instead redirect):

RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule ^events/year/2011-06-1.html - [G]
RewriteRule ^events/day/2010-06-01.html – [G]
..........

Do not use both "RewriteRule" and "Redirect" in the same server unless you control the server and can specify the Apache module execution order.

Yes, I have control over my server, can you tell me please, where are these settings?

Konstantin

g1smd

9:31 pm on Aug 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It is far easier to simply use RewriteRule for all of the rules and not use the Redirect directive at all.

jdMorgan

1:08 am on Aug 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On Apache 1.3.x, modules execute in the reverse order in which they are loaded.

On Apache 2.x, some ill-defined "priority scheme" is used. I guess you'd have to hack the code and recompile it to change it.

If you want a rewritecond to apply to two rules, then it must appear in both rules. Or you could combine the rules:

RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteCond $1 ^events/year/2011-06-1\.html$ [OR]
RewriteCond $1 ^events/day/2010-06-01\.html$
RewriteRule ^(.+\.html)$ – [G]

Note that all literal spaces in regex patterns should be escaped as shown.

Jim