Hi I tried various methods with modewriter in htaccess shown in other threads. I want to redirect my url from www.example.com/categories.php?category=1 to www.example.com/categories/science.
I would really appreciate an example too where I'm wrong. Thank You.
Assuming that it is just this one URL you want to redirect it would be like:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^category=1$ [NC]
RewriteRule ^categories.php$ www.example.com/categories/science/? [L,R=301]
This is in case you are using a .htaccess file, otherwise add a prepending slash:
RewriteRule ^/categories.php$ www.example.com/categories/science/? [L,R=301]
The querystring wil be discarded. Only put [R] if you want to show it to the user in the addressbar of the browser. Consider which status you want to serve, Google likes 301 if it's permanent.
Next you have to catch the incoming request with an index.php in the directory www.example.com/categories/science
good luck!
Related
Unfortunately I didn't get it solved by myself and need to ask for help. I want to redirect all urls which follow a certain pattern (in this case it contains "reviews/category"). These URLs supposed to be redirect to another url which is made up the first one:
http://[product-url]/reviews/category/[category-url]
supposed to be redirect to
http://[product-url].html
Furthermore it shouldn't matter if you call the url with or without www.
Example:
http://example.com/ford-blues/reviews/category/cars supposed to be redirect to http://example.com/ford-blues.html
Any help would be much appreciated.
Following code isn't working
RewriteEngine On
RewriteRule ^reviews/category/?$ $1\.html [R=301,L]
Try:
RedirectMatch 301 ^(.*)/reviews/category/ /$1.html
in the htaccess file in your document root.
Or using mod_rewrite:
RewriteEngine On
RewriteRule ^(.*)/reviews/category/ /$1.html [L,R=301]
I want to make some redirects in htaccess. I will explain in detail what I'm trying to do and at the end I will tell you my question, so if you don't want lots of explains just scroll down.
So for you to understand what I am doing, here is an example: if I enter www.mysite.com/oldpage it should redirect me to www.mysite.com/new page. For this I used:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
Redirect /oldpages http://www.mysite.com/newpages
The problem is that I want to use this for more than one page. So I want that:
mysite.com/oldpage/firstarticle
to redirect to
mysite.com/newpage/firstarticle
And the same with all articles. I want to redirect all like:
Redirect /oldpages http://www.mysite.com/newpages
Redirect /oldpages/firstarticle http://www.mysite.com/newpage/firstarticle
Redirect /oldpages/secondarticle http://www.mysite.com/newpage/secondarticle
But I have a conflict because Redirect /oldpage works on every case.
That's why (AND HERE IS WHAT I DON'T HOW TO DO!!!) I need to use a general rule like:
Redirect /oldpage/(*) http://mysite.com/newpage/(*)
Redirect /oldpage/(any numeric characters-don't need them)/(*) http://mysite.com/NEWSINGLEPAGE/(*)
Instead of (*) it should be any characters,but use them in the new link.
Does someone know how to make this Redirect for more than one page?
Thank you for your time!
!!!!
I DON'T KNOW IF IT'S POSSIBLE BUT IT WOULD BE NICE IF I COULD USE AN IF STATEMENT IN HTACCESS...SOMETHING LIKE:
if (adress is /redirect) Redirect to newpage.html;
else if (adress is /redirect/(some number)/(.*)) Redirect to NEWSINGLEPAGE/$1.html
else if (adress is /redirect/(.*)) Redirect to newpage/$1.html
Change
Redirect /oldpage/(*) http://mysite.com/newpage/(*)
To
RedirectMatch /oldpage/(*) http://mysite.com/newpage/$1
try this
RewriteRule ^oldpage/(.*)$ /newpage/$1 [R=301,L]
I want to make a existing site seo friendly URLs. I have almost there and rewrite all links. But when it comes to 301 redirect old URL's to new ones, where I got stuck. Here below how I have done it.
RewriteEngine On
RewriteRule ^video_gallery video_gallery.php
Redirect /video_gallery.php http://site.com/video_gallery
So as illustrated above I have rewritten the video_gallary.php to video_gallary and now I want to redirect all requests with http://site.com/video_gallery.php to http://site.com/video_gallery
But its now working properly as above. A lil help here please.
Thank you
This will cause a redirect loop. You need to match against the %{THE_REQUEST} variable which is the actual request, not the URI (which gets changed through the course of processing). So using your example:
RewriteEngine On
RewriteRule ^video_gallery video_gallery.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /video_gallery\.php
RewriteRule ^ /video_gallery [L,R=301]
We have an existing site, let's call it ourdomain.com. We moved content over from a site that is shutting down, let's call it legacydomain.com. We pointed the legacy domain at our server to the /public_html/ folder.
What I need is an .htaccess that will redirect legacydomain.com or legacydomain/anything-here to ourdomain.com/legacydomain/ with nothing else appended to the URL.
However, I also need a few specific URLs to redirect to certain destinations, and they don't really follow a pattern. For example:
legacydomain.com/something.html to ourdomain.com/legacydomain/something.html
legacydomain.com/another.html to ourdomain.com/legacydomain/folder/another.html
This is what I have tried:
RewriteCond %{HTTP_HOST} ^www\.legacydomain\.com$ [NC]
RewriteRule (.*) http://www.ourdomain.com/legacydomain/$1 [R=301,L]
Redirect 301 /something.html http://www.ourdomain.com/legacydomain/another.html
It mostly works, but if I visit legacydomain.com/anything-here it doesn't even attempt to rewrite, it just keeps the domain the same and gives a 404. And also I have a feeling that even if it did work, something like legacydomain.com/anything-here/more-stuff would get rewritten as ourdomain.com/legacydomain/anything-here/more-stuff which I don't want.
Only other thing in the .htaccess is rewriting non-www to www, and the standard WordPress stuff. Any guidance would be greatly appreciated. Everything above should have an http:// and www in front for the examples, but it wouldn't let me post that many "links".
For each specific rewrite you would need two lines, as follows. Depending on your existing config you may need to add a slash at the beginning of the RewriteRule in front of something.html if this doesn't work.
RewriteCond %{HTTP_HOST} legacydomain.com
RewriteRule something.html http://ourdomain.com/legacydomain/something.html [R=301,L]
Then you would use a catch-all for everything else.
RewriteCond %{HTTP_HOST} legacydomain.com
RewriteRule (.*) http://ourdomain.com/legacydomain/ [R=301,L]
Personally, I would go for the simplest solution which doesn't use mod_rewrite. First, just redirect the specific pages to wherever they need to go.
Redirect 301 /something.html http://ourdomain.com/legacydomain/something.html
Redirect 301 /another.html http://ourdomain.com/legacydomain/another.html
Then, simply redirect everything else to the base URL.
RedirectMatch 301 (.*) http://ourdomain.com/legacydomain/
These must be put in your .htaccess file before the RewriteEngine on statement.
I have this url
http://www.mmametals.com.php5-20.dfw1-1.websitetestlink.com/?page_id=61
and i want to redirect to the root like this
http://www.mmametals.com.php5-20.dfw1-1.websitetestlink.com
here is my htaccess
RewriteEngine on
redirect 301 /?page_id=61/ http://www.mmametals.com.php5-20.dfw1-1.websitetestlink.com
but nothing is happening...any ideas
Also I was wondering if there is a way also in .htaccess to delete a duplicate /about ...so for example if the url is
http://somesite.com/about/about
it will rewrite the rule to always be
http://somesite.com/about
RewriteEngine On
RewriteCond %{QUERY_STRING} ^page_id=61$
RewriteRule (.*) http://www.mmametals.com.php5-20.dfw1-1.websitetestlink.com? [R=301,L]
RewriteCond %(REQUEST_URI) ^/about/about[/]?
RewriteRule (.*) http://somesite.com/about? [R=301,L]
should do it.
I don't know the exact answer off the top of my head as I don't work directly with apache that much any longer, but I think you need to look into apache's mod_rewrite module. Try taking a look at:
Apache's mod_rewrite documentation
This post about blocking certain URLS