How do I rewrite and use only one version of the url? - .htaccess

I have the following rewriterule:
RewriteRule ^first-test-page/?$ testing.php?idPage=1 [NC,L]
How do I redirect the user to domain.com/first-test-page/ if he goes to domain.com/testing.php?idPage=1 ?
Thank you!

You need a two rules. This should work for you. Give this a try.
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /+testing\.php\?idPage=1
RewriteRule ^ /first-test-page? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^first-test-page/?$ /testing.php?idPage=1 [NC,L]

Related

Redirecting to without .html

So I have already this in my .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Now if someone enters:
example.com/test.html
how can I redirect him to:
example.com/test
i tried:
redirect /test.html /test
but it gave me Page is not redirecting properly...
You need another rule. Replace your current rule with this and see how it works for you.
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /(.+)\.html [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [NC,L]

htaccess - 301 redirect

I want to redirect
http://www.mysite.com/index.php?channels=browse&channel_id=1&sort=rated
to
http://www.mysite.com/category/cars/?r_sortby=highest_rated&r_orderby=desc
Can someone to help-me with this issue?
Thank you!
This should work for you
RewriteEngine on
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index\.php\?channels=browse&channel_id=1&sort=rated\ HTTP
RewriteRule ^ /category/cars/?r_sortby=highest_rated&r_orderby=desc? [R=301,L]
EDIT:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/category/(.*)
RewriteRule ^(.*)$ /watch.php?tag=$1 [L]

how to use mod_rewrite .htaccess

Hello i want to rewrite the following link:
http://websoftit.ro/social/profil.php?user=Ancuta Mirela
to http://websoftit.ro/social/Ancuta Mirela.
Can someone tell me how to do that with mod_rewrite also maybe give me a link to a good documentation to learn myself how to do that?
Thnx in advance.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+social/profil\.php\?user=([^\s&]+) [NC]
RewriteRule ^ /social/%1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^social/([^/]+)/?$ /social/profil.php?user=$1 [L,QSA]
I would suggest http://askapache.com as a good reference for learning mod_rewrite.
RewriteEngine On
RewriteRule ^social/([^/]+)$ social/profil.php?user=$1
RewriteCond %{QUERY_STRING} (?:^|&)user=([^&]+) [NC]
RewriteRule ^ http://websoftit.ro/social/%1 [NE,R=301,L]

URL Rewriting syntax IIS 8 ISAPI Rewrite 3

I had a previous post regarding this matter:
ISAPI_Rewrite and Coldfusion Rules
With the help of Helicon Support we were able to create the following rules:
RewriteEngine on
RewriteRule on
RewriteBase /
RewriteCond %{QUERY_STRING} ^filter=brand&brand_id=([^&]+)&brand_name=([^&]+)$ [NC]
RewriteRule ^products-search\.cfm$ /search/%1/%2.cfm? [NC,R=301,L]
RewriteCond %{QUERY_STRING} ^$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^search/([^/]+)/([^._]+)\.cfm$ /products-search.cfm?filter=brand&brand_id=$1&brand_name=$2 [NC,L]
RewriteCond %{QUERY_STRING} ^product_id=([^&]+)&product_title=([^&]+)$
RewriteRule ^product-details\.cfm$ /%1/%2.cfm? [NC,R=301,L]
RewriteCond %{QUERY_STRING} ^$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^._]+)\.cfm$ /product-details.cfm?product_id=$1&product_title=$2 [NC,L]
Their help was much appreciated as i am very new to URL Rewriting. The issue i am having now is that the first rule works, it turns the url from:
www.mysite.com/products-search.cfm?filter=brand&brand_id=98&brand_name=HAMANN
to
www.mysite.com/search/98/HAMANN.cfm
Since i am new to this, i do not understand how to get the css/js/images folders to display on this page, what rule or condition do i use for the RewriteBase / part so that everything on the page loads correctly?
The second part of the .htaccess rules do not actually work which change:
product-details.cfm?product_id=1&product_title=This Is A New Product
to
products/This_Is_A_New_Product.cfm
Any help would be greatly appreciated

language redirect from GET parameter htaccess

I have this code, it redirecs www.example.com?index.php?q=home&lang=en into www.example.com/home. I would like to redirect it into www.example.com/en/home. Is it possible?
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php?q=$1&lang=$2 [L,QSA]
RewriteRule ^([^/]*)(.*)$ $1[L,QSA]
Thanks in advance
Try:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]{2})/(.*)$ /index.php?q=$2&lang=$1 [L,QSA]

Resources