I have recently removed a module from Magento that created vanity URL, for filtered searches.
When I've removed this module its now using URL parameters for all filtered navigation pages.
I want to redirect all of these vanity urls to the same page without the vanity part of the URL.
An example of a URL that I want redirecting is:
/hand-dryers/high-speed/shopby/brand-jet_towel-ultradry-magnum_multi_dri-dyson/handdryer_dryingtime_seconds-under_10_seconds/
Redirecting to
/hand-dryers/high-speed
The way the module worked would be by adding the string "shopby" and then converting each parameter into a readable format.
I need a rewrite rule to re-direct all URLs that contain "shopby" to the same URL but with everything from "shopby" removed
I hope this makes sense.
Look forward to hearing back from someone
Should work:
RewriteEngine on
RewriteRule (/.*)/shopby $1 [R=302,L]
After testing you can change the 302 to 301 to ensure the old URLs are pruned from search engine indexes.
Try this:
RewriteRule ^(.+?)/shopby/?.*$ $1/shopby [L]
Related
I'm trying to redirect all existing urls to a new slightly simplified url structure, and wish to keep the existing links that have been indexed on google/bing intact.
The current url for posts looks like this /blog/post/some-random-post-here the
new post url's are virtually the same but no longer have /post/ in them. Instead its /blog/some-random-post-here
I have created a new htaccess rule for the new urls. So as of now both versions of the url's work. However I wish to keep one copy for SEO reasons. This is on a blog made from scratch (this is not WordPress or other blogging softwares)
Here are the rewrite rules in my htaccess for old and new urls.
**OLD URL:** RewriteRule ^post/([^/]+)/$ index.php?controller=post&action=view&post=$1 [L]
------------------------------------------------------------------------
**NEW URL:** RewriteRule ^([^/]+)/$ index.php?controller=post&action=view&post=$1 [L]
What would I need to add to the OLD URL structure in order to make a 301 permanent redirect to the new url structure? Both the OLD and the NEW rewrite rules are still active. But I rather 301 the old rule to the new URL.
Thank you in advance.
You can use RedirectMatch directive for this url redirection, it's easy.
Try :
RedirectMatch 301 ^/blog/post/(.*)$ http://domain.com/blog/$1
Or Try mod_rewrite To remove query strings
RewriteEngine on
RewriteRule ^blog/post/(.*)$ http://example.com/blog/$1? [NC,R,L]
Empty question mark ? at the end is important as it will discard the original query string from url.
will 301 redirect
http://example.com/blog/post/foo
to
http://example.com/blog/foo
I am familiar with redirecting URLs that don't have file types at the end, but not with ones that have .php at the end.
The website I'm working on has hundreds of indexed pages on Google that have this at the beginning of the url: http://example.com/index.php? with more information trailing afterwards.
An example is: http://example.com/index.php?main_page=index&cPath=1_18
The new index of the website is http://example.com/index or http://example.com
If I put http://example.com/index.php as the URL to be redirected, will it also redirect all index.php? Or do I need to put http://example.com/index.php* as the URL to be redirected or http://example.com/index.php?*?
Thank you!
If the main script to be executed is index.php, then there is no point in redirecting a url to itself...
Aabout those GET parameters in the url, if index.php oesn't use them, then.... they will be useless, but... thats it XD
The point is: does everything work without redirecting? If so, why redirecting at all?
If there are 301 redirects, ... that will mean more request to the server, and for those clients with low bandwith it does make a difference.
BTW, take a look at: htaccessredirect
Try:
RedirectMatch 301 ^/index\.php$ /
(or)
RedirectMatch 301 ^/index\.php$ /index
The query string at the end will automatically get appended.
If you're using wordpress now, you're not going to be able to use the mod_alias directive like above. You'll need to use mod_rewrite and place these rules above the wordpress rules:
RewriteCond %{THE_REQUEST} \ /+index\.php
RewriteRule ^ / [L,R=301]
(or replace the / at the end with /index)
I got this url
/localhost/andalucia/productdetails.php?value=20
I want to change it to
/localhost/andalucia/productdetails/20
how do you do this and how will you get the value 20 in the handler page?
should I change the coding or I just add an ht access file?
If it is adding a ht access file what code should be in it?
How if I have more pages like:
/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus
Will they be affected automatically too?
ok i tried to use
RewriteRule ^productdetails/([0-9]+)$ productdetails.php?value=$1 [L,QSA]
but now the problem is all my pictures is gone in the html and i cant open the other page like
/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus
i need a htaccess code that can open all of these
/localhost/andalucia/product
/localhost/andalucia/home
/localhost/andalucia/contactus
/localhost/andalucia/productdetails/20
pls helpp someone
With the apache extension mod_rewrite it is really easy to transform your pretty URLs into the URLs needed by your script. This .htaccess example which you place in your web root should get you going:
RewriteEngine On
RewriteRule ^andalucia/productdetails/([0-9]+)$ /andalucia/productdetails.php?value=$1 [L]
This example will only rewrite andalucia/productdetails/NNNN... format URLs, all other URLs won't be affected. If you need to pass other query parameters, like /andalucia/productdetails/20?sort=asc you need to pass the QSA flag (query string append) to the rewrite rule:
RewriteRule ^andalucia/productdetails/([0-9]+)$ /andalucia/productdetails.php?value=$1 [QSA,L]
The L flag will prohibit the evaluation of next rules. Just look up the mod_rewrite documentation for a in-depth discussion!
On my site, users can add various URL's that need to be redirected.
For example; from this: domain.com/oldpage/36/
To this: domain.com/newpage/47/
They are added to the .htaccess like this:
Redirect 301 /oldpage/36/ /new-page/47/
But when accessing the old page they get this:
domain.com/newpage/47/?pid=36&pagename=oldpage
I'm pretty sure these rewrite rules are causing this predicament:
RewriteRule ([^.]+)/([0-9]+)/$ index.php?pid=$2&pagename=$1
RewriteRule ([^.]+)/([0-9]+)/([^.]+) index.php?pid=$2&pagename=$1&vars=$3
However, mod_rewrite stuff is not my strongpoint, so I have no idea how to fix it.
Any ideas ?
Adding a ? makes the Rewrite not add the query string to the url.
so this should work:
Redirect 301 /oldpage/36/ /new-page/47/?
As a precaution you could also add it to the end of:
RewriteRule ([^.]+)/([0-9]+)/$ index.php?pid=$2&pagename=$1?
RewriteRule ([^.]+)/([0-9]+)/([^.]+) index.php?pid=$2&pagename=$1&vars=$3?
But only if they are needed
Since you are already using mod_rewrite anyway, I suppose you should make your redirects using rewrites too
RewriteRule /oldpage/36/ /new-page/47/ [R=301]
This will "rewrite" the URL from old to new, and will redirect the browser to new url with status code 301. [R] directive means redirect, which also stops other rules from processing, hence the other rules will be handled only when the new request is sent from broswer with new url.
I have a basic CMS in PHP/MySQL where content managers can create pages to the system for public viewing. Each page is then available at an url such as http://www.example.com/pages.php?pid=123
Now, I want to redirect requests to http://www.example.com/pages.php?pid=123 to http://www.example.com/pages.php?pid=456.
I've already removed the pid=123 page from the db but because of the cms code the site still returns a 202 when some one tries to access the page. I thought I could use a 301 redirect in .htaccess to make the redirect work, i.e.:
redirect 301 pages.php?pid=123 http://www.example.com/pages.php?pid=456
but this doesn't work, Apache still return 202 when trying to fetch the pid=123 page. Also, I've tried using mod_rewrite, but it doesn't work:
RewriteRule ^pages.php?pid=123$ pages.php?pid=456 [R=301,L]
Any ideas what could be wrong and how I can fix the 301 redirect?
Both the Redirect and RewriteRule directive work just on the URL path. In mod_alias (Redirect directive) you can not test the query and in mod_rewrite (RewriteRule directive) you need an additional RewriteCond directive:
RewriteCond %{QUERY_STRING} (^|&)pid=123(&|$)
RewriteRule ^pages\.php$ /pages.php?pid=456 [R=301,L]
But it would certainly be better if your CMS can handle such redirects since it’s your CMS that knows best what URLs are valid and what are not.
You can perform the redirect in PHP (which probably knows more about what to redirect where) using header().
Please note that ? is a special character used by regular expressions, so your regex matches pages.phppid=123 and pages.phppid=123.
Even then, I don't think the query string (including the ?pid=123 part) is used in the URL handled by RewriteRule, so you would need to use something like:
RewriteCond %{QUERY_STRING} ^pid=123$
RewriteRule ^pages.php$ pages.php?pid=456 [R=301,L]
This shouldn't work as is, but it should give you some ideas.