Forum Moderators: phranque

Message Too Old, No Replies

.htaccess file failed to rewrite URLs

My .htaccess file have rewrite rules but engines also crawling real URLs

         

neo2sxn

6:07 pm on Oct 11, 2014 (gmt 0)

10+ Year Member



Hi guys !

I am using rewriting rules to redirect some URLs, but search engines crawling both URL (Rewritten and Real URLs).

For example :

Real URL : www.example.com/storecoupon.php?cid=Flipkart

Rewritten URL : www.example.com/coupon/Flipkart.html

Search Engines are crawling both URLs, even i want search engines to index only Rewritten URLs (http://www.example.com/coupon/Flipkart.html)

This is happening with all the URLs...

Below are the codes that i am using on my .htaccess file :

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule index.html$ index.php [NC,QSA,L]
RewriteRule allstore.html$ allstore.php [NC,QSA,L]
RewriteRule printable.html$ printable.php [NC,QSA,L]
RewriteRule coupon/([a-zA-Z0-9_-]+).html$ storecoupon.php?cid=$1 [NC,QSA,L]
RewriteRule category/([a-zA-Z0-9_-]+).html$ categorystore.php?cid=$1 [NC,QSA,L]
RewriteRule pages/([a-zA-Z0-9_-]+).html$ cms.php?id=$1 [NC,QSA,L]

RewriteRule print/([a-zA-Z0-9_-]+).html$ printcoupon.php?cid=$1 [NC,QSA,L]
RewriteRule newsletter.html$ newsletter.php [NC,QSA,L]
RewriteRule newslettererror.html$ newslettererror.php [NC,QSA,L]

RewriteRule offers/([a-zA-Z0-9_-]+).html$ detail-page.php?cid=$1 [NC,QSA,L]
RewriteRule submit.html$ submit.php [NC,QSA,L]
RewriteRule contactus.html$ contactus.php [NC,QSA,L]
RewriteRule List-Your-Business-On-CatchCoupon.html$ List-Your-Business-On-CatchCoupon.php [NC,QSA,L]
RewriteRule sitemap.xml$ sitemap.php [NC,QSA,L]
RewriteRule listing/([a-zA-Z0-9_-]+).html$ comment.php?id=$1 [NC,QSA,L]

[edited by: Ocean10000 at 6:12 pm (utc) on Oct 11, 2014]
[edit reason] Examplified [/edit]

lucy24

6:35 pm on Oct 11, 2014 (gmt 0)

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



:: shudder ::

First and most important:

I am using rewriting rules to redirect some URLs

No. You're not. All the quoted rules are for rewriting URLs from a short-and-pretty form to a long-and-ugly form. About which more later.

There are no rules to create redirects in the other direction. This is fine up until the moment that someone-- in this case a search engine-- learns that your "real" URLs exist. Now they will ask for both. So you will have to add a whole new batch of rules, before the ones creating the rewrite, all in this form:

RewriteCond %{THE_REQUEST} \?
RewriteRule long-icky-URL-here http://www.example.com/short-pretty-URL-here [R=301,L]

where the condition means "the ? query string was present in the original request and is not the product of my own rewriting". Speaking of which...

#1 What's the QSA for? Isn't the whole point of short pretty URLs that there is no visible query string? There's not much sense in rewriting if there's going to be a query either way.

#2 Never, ever use [NC] in a rule that creates only an internal rewrite. (Exception: If you're rewriting to a php-or-similar script that will itself check casing and issue a 301 or 404 as appropriate.) Your users should be asking for /offers/ not for /OFFERS/ or /Offers/ or /OfFerS/ or, or, or. (Duplicate content is bad enough. The [NC] flag creates 2^n possibilites, where n is the number of alphabetic characters in the URL.)

Oh, and incidentally: There's a whole slew of RewriteRules that can be collapsed into one: the rules that quietly rewrite .html to .php. They could all be fused into (using your examples)

RewriteRule ^(allstore|printable|newsletter(error)?|submit|contactus|List-Your-Business-On-CatchCoupon)\.html /$1.php [L]


Note the leading / in the target. Get in the habit of using it here and you'll never have to think about a RewriteBase.

Note also that I've omitted one item. Requests for "index.html" should NOT be rewritten. They should be redirected to / alone, and then the DirectoryIndex takes over.

Literal periods . in the pattern should be escaped. In this particular set of rules it isn't a lethal error, but do it as a habit.

neo2sxn

1:55 pm on Oct 12, 2014 (gmt 0)

10+ Year Member



Hi there,

Sorry but i purchased the script from codecanyon.
asking for the support from there was waste of time only. I am not professional in this, please can you correct my codes so that these can work as i want ?

not2easy

3:16 pm on Oct 12, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



The place to start is in the forum Charter: [webmasterworld.com...]