Forum Moderators: phranque
Here is what I have:
Redirect /c1/9/id/3.*.html http: //www.myexamplesite.com/c1/9/id/3.superwidgets.html
(the space between http: and // is not there in the real htaccess file)
As you can see I want to send users that request
/c1/9/id/3.oldwidgetarticle1.html
/c1/9/id/3.widgetnonsene.html
/c1/9/id/3.morewidgetnonsense.html
/c1/9/id/3.whattheheck.html
etc..
to /c1/9/id/3.superwidgets.html
With the above line in my .htaccess file forwarding doesn't work. Is this caused by bad syntax or by another line in my .htaccess, namely this one:
Rewriterule ^c([0-9]+)/([0-9]+)/id/([0-9]+).*.html id.php?id_id=$3
Use RedirectMatch [httpd.apache.org], not Redirect, and then use either mod_alias or mod_rewrite to keep things simple.
Jim
I used this:
RedirectMatch (3\.oldwidgetnonsense)\.html$ http: //www.websiteaddress.net/c1/9/id/3.newwidgetnonsense.html
What I want is actually more advanced than I indicated in my first post.
I use static URLs on my pages and rewrite them to dynamic ones with the following lines:
RewriteEngine on
Options FollowSymlinks
RewriteRule ^c([0-9]+)$ artcat.php?article_type=$1
RewriteRule ^c([0-9]+)/([0-9]+)/([0-9]+).*.html article.php?article_type=$1&article_id=$2&pagenumber=$3
Rewriterule ^c([0-9]+)/([0-9]+)/id/([0-9]+).*.html id.php?id_id=$3
With these lines in the .htaccess file
[websiteaddress.net...] will load the same page as [websiteaddress.net...]
This is not good, because whenever I make a typo in a URL (newidgetnonsense) I create a double page on my site for which you can get penalized by Google / Adsense.
What I need is a .htaccess rule that will redirect (permanent) all typo's and old pages to the right page. I would have to use one line for every page, but that's ok. So /c1/9/id/3.anything.html should go to /c1/9/id/3.the_right_page_specified_by_me.html and after that the correct URL must be converted to a dynamic URL with the rewriterules above.
Would that be possible in this order? Do you perhaps know an article that explains this situation in depth? I find it quite difficult to build this from small examples and code snippets.
RewriteRule /3\.oldwidgetnonsense\.html$ http://www.example.com/c1/9/id/3.newwidgetnonsense.html? [R=301,L]
The [L] flag stops mod_rewrite processing if the rule matches and the rewrite is performed. You should use [L] on all rules for URLs that do not require processing by the rules that follow them. Otherwise, you'll slow down your server unnecessarily.
As to the rest, almost anything is possible using mod_rewrite, but you have to be very specific about how your old URLs map to new URLs.
The following references may be useful:
Apache mod_rewrite documentation [httpd.apache.org]
Apache URL Rewriting Guide [httpd.apache.org]
Regular Expressions Tutorial [etext.lib.virginia.edu]
Jim