htaccess rewrite rule redirect - .htaccess

I have some old urls
http://www.website.com/result/?q=&result=1
http://www.website.com/result/?q=&result=2
http://www.website.com/result/?q=&result=3
http://www.website.com/result/?q=&result=4
etc.. probably going up to about 60
Is there anyway I can create one rule that redirects any query that looks like this to the home page /home/ instead of my trying to redirect all of them individualy?
Thanks in advance

yes, i suppose you are using apache HTTPD. In your server configuration you can define an regular expression which filter the pattern you want. For example:
<FilesMatch "/site/*">
...
</FilesMatch>
Define a RegExp and tell where to redirect or what to do.
Hope this helps, Cheers

Related

RewriteRule from download.php?token=something into /download/something

I am working on url, I try htaccess, php, javascript and many other things but unable to figure it out.
My url is :
example/cheap-flight-to.php?country=lagos
and I want to change the url something like this :
example/cheap-flight-to.lagos
or
example/cheap-flight-to/lagos
please help me
The following should allow you to generate your urls in the format that you wish.
RewriteEngine On
RewriteBase /
RewriteRule ^example/cheap-flight-to/([a-zA-Z]+)$ /example/cheap-flight-to.php?country=$1 [NC,L]
What you want could be done using regular expressions in .htaccess, but it makes no sence, since it wouldn't be pointing to anything, unless you have a directory cheap-flight-to/lago in which you have an index.php that will show-up in the browser or return data. This means you have to setup a directory for each destination you want to go to. Is that really what you want? Usually it's been used the otherway around. The user (or a script for that matter) enters a url like "example/cheap-flight-to/lagos". Then through regular expressions in .htaccess you rewrite the url to "example/cheap-flight-to.php?country=lagos".
Have a look at http://httpd.apache.org/docs/1.3/misc/rewriteguide.html and
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html for more on rewriting rules in .htaccess.

.htaccess rewrite rule from mydomain.com/contact.htm to mydomain.com/contact

I guess this was a very common and simple .htaccess rewrite rule, however I wasn't able to google a solution for it.
So, the question is in the title already, how can I rewrite the address to change it from example.com/contact.htm to example.com/contact? The rule would of course not be only for just the contact.htm but for any page in the website. No need to worry about GET variables, since I won't be using any.
[ Also, do you think this is or might be considered a good practice or not really relevant? ]
Thanks.
Try this:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^contact.htm$ /contact
This should serve contact.html when requesting example.com/contact/
You could consider using MultiViews. You'll need to load the content negotiation module and turn MultiViews on, then Apache will automatically look for a file with an extension (there's a priority list in case you have both .html and .htm files with the same name for instance).

htaccess rewrite remove filename

How can I change url in this way using htaccess?
http://www.domain.com/index.html?page=home
http://www.domain.com/indexf6f2.html?page=blog
To
http://www.domain.com/?page=home
http://www.domain.com/?page=blog
You could try to generate your own .htaccess file based on your rules using this site http://cooletips.de/htaccess/ .
Regards, Hiawatha
I am not giving exact solution. Just utilize the followings, then you will be able to solve other URL rewriting using .htaccess
Take help from the following URL
http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html
Other important regarding rewriting through .htaccess
http://corz.org/serv/tricks/htaccess2.php
RewriteRule to rename URL?
For a nice basic
http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html

htaccess to remove print.html from url

We are currently hosting a large joomla site.
Google has indexed hundreds of the "print" versions of our pages.
for example if we have an article with the url:
www.mysite.com/funnyarticle.html
the joomla site automatically created:
www.mysite.com/funnyarticle/print.html
We have moved the site and deleted these pages, so they now get a 404 error from google.
We would like to redirect or rewrite (not sure what is the correct terminology) the "print" urls to their respective articles.
I would like to use htaccess to remove:
/print.html
and replace it with:
.html
I have seen examples but cannot get them to work correctly.
So I was hoping I could get specific advise on how to remove and replace the exact code above.
Thanks for your time.
Regards,
Aforantman
You can create a robot.txt file with following lines.
User-agent: *
Disallow: /*/print.html
this will disallow search engine robots to access files with name print.html.
You probably want to use a RewriteRule. See Apache's guide on how to use them: http://httpd.apache.org/docs/2.0/rewrite/rewrite_guide.html
But if you just want Google (and other search engines) to ignore those print versions, put a corresponding entry in you robots.txt. That way you don't need to fiddle around with Joomla's way of generating and accessing the print version for your human visitors.
You need to put these lines in your DOCROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*?)/print.html $1.html [L,R=301]
This will redirect any Google user clicking through to one of these pages to the correct article. If your article names can contain / then remove the ? from the above; the rule will still work but might take a few more μS runtime :-)
You can use robots.txt as said by Jishnu.This is the best way to do this.
User-agent: *
Disallow: /*/print.html

.htaccess url masking

I have a couple of wordpress urls that I want to simplify for SEO purposes. I have
http://www.example.com/fr/product-fr/review-fr/
I would like to change that to http://www.example.com/fr/product/review/ (remove -fr) but without changing the URL internally. So the user would access http://www.example.com/fr/product/review/ but the server would serve the content of http://www.example.com/fr/product-fr/review-fr/.
I want to do this to get around a URL problem with Wordpress and WPML.
Appreciate the help
Assuming the two letter lang code is always going to be constant throughout the URL:
RewriteEngine on
RewriteRule ^([A-Za-z]{2})/product/review$ /$1/product-$1/review-$1 [L,QSA]
should work a treat :)
P.S. the regexp takes any two-letter code (upper or lower case) so will work with other langs should you require.
Have you tried mod_rewrite and Rewrite rules?
Try:
^/([a-zA-Z]{2})/([^\/]+)/([^\/]+)/$ /$1/$2-$1/$3-$1
Haven't tested this though..

Resources