Forum Moderators: phranque

Message Too Old, No Replies

Newbie needs help with htaccess

         

mutualtrust

11:46 am on Jun 3, 2010 (gmt 0)

10+ Year Member



Ok. My problem is I just re-done my website. Not even 30 minutes after uploading my pages already appear in the search engine.

The link format on my site looks like this

[site.com...]
[site.com...]

but the way it appears in the search engine is like this:

[site.com...]
[site.com...]


Can someone please tell me how to do a htaccess rewrite for this.

I tried these but they did not work.

RewriteEngine On
RewriteCond %{QUERY_STRING} q=(.*)
RewriteRule /?q=(.*)$ /index.php/q=(.*)? [R=301,L]

RewriteEngine On
RewriteCond %{QUERY_STRING} q=([^/.]+)
RewriteRule /?q=([^/.]+)$ /index.php/q=(.*)? [R=301,L]

g1smd

6:51 pm on Jun 3, 2010 (gmt 0)

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



RewriteRule can only see ONLY the path part of the URL.

You will therefore need a preceding RewriteCond looking at QUERY_STRING.

The redirect target should include the protocol and domain name.

Your URL should NOT include the index.php element. It is best to strip it out, not include it.

Where you capture part of a request in a pattern like (.*) "on the left", you will re-use that value as the $1 back-reference "on the right".

mutualtrust

7:19 pm on Jun 3, 2010 (gmt 0)

10+ Year Member



Sorry but I dont understand htaccess I am new.. But is this what you mean?

RewriteEngine On
RewriteCond %{QUERY_STRING} q=(.*)
RewriteRule /?q=(.*)$ /(.*)/q=(.*)? [R=301,L]

jdMorgan

1:28 pm on Jun 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Three comments:

This is likely NOT an application for a redirect, but rather for an internal rewrite.

If you really do want to redirect the client (change the address in the user's browser address bar and change the URL shown in search results), then I'd recommend that you NOT include the "/index.php" URL-path-part, and simply use "/".

The example.com/q=xyz format is NOT a query string. It is a URL-path with an invalid character in it; The "=" character will have to be encoded to %3D to be passed through HTTP in the URL-path-part.

Rather that continuing this list with further guesses, I think it would be best to ask, "What are you trying to accomplish here?" Are the URLs wrong, or are you simply trying to "connect" new search-friendly URLs back to an existing page-generation script filepath?

If the latter, look into getting rid of the "q=" in the new search-friendly URLs, or at least replacing the "=" with a character that is allowed in a URL-path, such as a hyphen.

Jim