ISAPI Rewrite Syntax Help - isapi-rewrite

I have rebuilt a website from php into ASP.NET and need to redirect all the old horrible page URL's to the root of the new site - The old site just used index.php and print.php then LOADS of querystring values - So I have the following rules
RewriteRule ^print.php$ http://www.mynewsite.co.uk [R=301,L]
RewriteRule ^index.php$ http://www.mynewsite.co.uk [R=301,L]
Problem I have is it is 301 redirecting but appending all the crappy querystrings to the end of the domain - for example
http://www.mynewsite.co.uk?crap=45&more&7698097987 etc...
How do I tell ISAPI not to take the Querystrings and just redirect to the root URL?

The rules should be like this:
RewriteRule ^print.php$ http://www.mynewsite.co.uk? [R=301,L]
RewriteRule ^index.php$ http://www.mynewsite.co.uk? [R=301,L]
Notice the "?" at the end of substitution.

Related

.htaccess redirect www to non-www url doesn't not apply on the other link than the index

I've a Mac server and everything working fine
I'm running a wordpress and have .htaccess to rewrite the rule for custom link and so on
right now I'm having a trouble once I visit my site
http://www.mysite.com/anypage.html This doesn't work and give me page not found error
but if I visit same page but removed the www http://mysite.com/anypage.html this will work fine
So I thought I will make sure if this happen to all the pages and it was having the problem with all the pages except the home page so if I visit http://www.mysite.com or http://mysite.com neither one will work
I tried with many .htaccess rewrite rules and non of them word
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ %{HTTP_HOST}$1 [C]
RewriteRule ^www\.(.*)$ http://$1 [L,R=301]
Please suggest what is the problem.
Thanks
All your www will be redirected to now www URLs.
Just do this and try:
RewriteCond %{HTTP_HOST} ^www\.(mysite\.com)/?$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L]

decoding mod_rewrite charactors

I'm attempting my first pretty url implementation via mod_rewrite. Just want to check if I'm on the right track. I'm doing it via dev environment.
I'm trying to get www.cysticlife.dev/Profile.php?id=34 to become www.cysticlife.dev/34/Profile
Would the regex mod_rewrite version then be:
RewriteEngine on
RewriteRule ^/([0-9]+)/?/Profile$ www.cysticlife.dev/Profile.php?id=$1 [L]
Thanks in advance.
RewriteEngine on
RewriteRule ^/([0-9]+)/Profile/index.html$ /$1/Profile [R=301,L]
RewriteRule ^/([0-9]+)/Profile/$ /$1/Profile [R=301,L]
RewriteRule ^/([0-9]+)/Profile$ www.cysticlife.dev/Profile.php?id=$1 [L]
The "?/" wasn't needed.
The lines I added makes both www.cysticlife.dev/34/Profile, www.cysticlife.dev/34/Profile*/* and www.cysticlife.dev/34/Profile*/index.html* work (with a 301 "Permanently moved" redirection so only one of the three urls is indexed by search engines).
Sidenote: You don't need to specify the full url for your rewrite. You could easily replace the last one with:
RewriteRule ^/([0-9]+)/Profile$ www.cysticlife.dev/Profile.php?id=$1 [L]

mod_rewrite not redirecting for multilingual site when trailing slash missing

I am currently developing a multi-lingual website. Users can access the front page using URL with format below:
http://example.com/en/
http://example.com/fr/
Problem is here. URL without last "/" (http://example.com/fr) caused page not found problem
Here is the rule
RewriteRule ^/?([^./]+)/(.*)$ $2?lang=$1 [L,QSA]
Try this:
RewriteRule ^/?([a-z]{2})(/(.*))?$ $3?lang=$1 [L,QSA]
Another option would be to redirect if the trailing slash is missing:
RewriteRule ^/?[a-z]{2}$ %{REQUEST_URI}/ [L,R=301]

Rewrite URL on submit form

I have a search form and when I make a search I get this URL "http://****/video/view/search/?imeto_tam=tarsene" but I want to replace this the "?imeto_tam=tarsene" with the word I search for and my address to look like this - "http://****/video/view/search/tarsene". Generally I use mod_rewrite on my site and it's working for my links but it's not working for the form-s. Could someone tell me how to do it?
RewriteEngine On
RewriteRule ^view/([0-9a-zA-Z\-\(\)]+)/?$ index.php?a=$1 [L]
RewriteRule ^view/([0-9a-zA-Z\-():]+)/([0-9a-zA-Z\-():\.,]+)$ index.php?a=$1&id=$2 [L]
These rules would go into your root .htaccess file and 301 redirect the querystring imeto_tam to the folder and then the next rule would make it get passed to your code (index.php)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?imeto_tam=([^&]+)(&.*)?$ [NC]
RewriteRule ^video/view/search/(index\.php)?$ /video/view/search/%2/? [R=301,L]
RewriteRule ^video/view/search/([^/]+)/$ /video/view/search/index\.php?imeto_tam=$1 [L]

rewriting single url help

I'm trying to rewrite the following url:
index.php?route=checkout/cart
to
/cart
using:
RewriteRule ^index.php?route=checkout/cart$ /basket [L]
However it doesn't seem to work. Anyone know what I'm doing wrong?
Thanks
RewriteRule does only test the URL path. You need RewriteCond to test the query:
RewriteCond %{QUERY_STRING} ^route=checkout/cart$
RewriteRule ^index\.php$ /basket [L,R=301]
The additional R=301 flag will cause an external redirect with the status code 301 (permanent redirect) instead of an internal redirect.
And if you want the other way round:
RewriteRule ^basket$ index.php?route=checkout/cart [L]
You need to send a redirect so that the new URL get reflected in browser address bar. So, add R to the [L].
RewriteRule ^index.php?route=checkout/cart$ /basket [R,L]
If you'd like that searchbots should ignore the "ugly" URL and/or remove it from the indexes and use the new instead, then send a 301 redirect.
RewriteRule ^index.php?route=checkout/cart$ /basket [R=301,L]

Resources