apache rewrite don't redirect? - mod-rewrite

apache .htaccess
RewriteRule ^promotion\.php\?do=content&id=38&mail$ promotion\.php?lang=tc&do=content&id=38 [R,L]
Thank you.

To match the query string, you have to use %{QUERY_STRING} like shown below.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^do=content&id=38&mail$ [NC]
RewriteRule ^promotion\.php$ promotion.php?lang=tc&do=content&id=38 [R,L]
Put it in the folder where promotion.php is present. I'm not sure how to involve RewriteCond ${HTTP_HOST} above.

Related

Basic rewrite of url

I need a rule that rewrites
http://example.com/page.html?page=2
to
http://example.com/page.html/page/2
I already tried this rule:
RewriteRule ^(.*)page=(.*)$ http://example.com/$1/page/$2/
but this does not work! :( Where I'm wrong?
You can try this one:
RewriteCond %{QUERY_STRING} page=(\d+) [NC]
RewriteRule (.*) /$1/page/%1/? [R=301,L]
It should works.

https redirect with .htaccess

I want to change my domain name http://flexy.tk to https://flexy.tk and I don't know what to edit in this .htaccess file I am new so plz help in detail and I don't want to get any risk but I try I changed the last line from http to https but I don't know is it working or not so thanks in advance
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.flexy\.tk$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^/?$ "http\:\/\/flexy\.tk\/" [R=301,L]
before giving downgrade try to help first friend
Just do it like this:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

Isapi additional url variables

i wish to add more url variables to my url... whatever there is after ? i wish to retrieve it as a urls variable Thank YOU!
RewriteRule ^(.*).html?(.*)$ products.cfm?categ=$1&urls=$2 [NC,L]
RewriteRule ^products.cfm?categ=(.*)&urls=(.*)$ (.*).html?(.*) [NC,R=301,L]
RewriteCond %{QUERY_STRING} ^condition=(\d+)&maxprice=(\d+)&minprice=(\d+)&persons=(\d+)&maxyear=(\d+)&minyear=(\d+)&order=(\d+)$ [NC]
RewriteRule ^category/(.*).html$ products.cfm?categ=$1&condition=%1&maxprice=%2&minprice=%3&persons=%4&maxyear=%5&minyear=%6&order=%7? [NC,L]

RewriteCond %{REQUEST_URI} not working

I am trying to redirect all requests coming in to the web server as http://portal.company.com/legacy to http://portal.company.com/wps/portal/public/legacy/legacyportlet with the following rule, but it is not working as expected.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^portal\.company\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/legacy$ [NC]
RewriteRule ^(.*)$ /wps/portal/public/legacy/legacyportlet$1 [NC,L,PT]
I have also tried
RewriteCond %{HTTP_HOST} ^portal\.company\.com$ [NC]
RewriteRule ^/legacy /wps/portal/public/legacy/legacyportlet [NC,L,PT]
Any help would be greatly appreciated!
Thanks
It doesn't look like your source or target URLs change in any way, so possibly you're better off using Apache's basic Redirect directive which just redirects one URL to another.
Use this rule:
RewriteCond %{HTTP_HOST} ^portal\.company\.com$ [NC]
RewriteRule ^legacy/?$ /wps/portal/public/legacy/legacyportlet [NC,L]
Remember that in .htaccess RewriteRule doesn't match leading slash of URI.

Problem with RewriteCond %{QUERY_STRING}, backreference not dispaying in final URL

I have the following in my .htaccess file:
RewriteCond %{QUERY_STRING} ^route\=product\/category\&path\=35\&page\=([0-9]+)$
RewriteRule ^index\.php$ http://%{HTTP_HOST}/product/category/35/page_$1? [R=301,L]
It's not behaving as expected though, when I enter the URL:
http://example.com/index.php?route=product/category&path=35&page=2
It gets rewritten to:
http://example.com/product/category/35/page_
Could someone tell me what I have done wrong please?
Thanks,
eb_dev
To reference submatches of a RewriteCond directive, you need to use %n instead of $n:
RewriteCond %{QUERY_STRING} ^route=product/category&path=35&page=([0-9]+)$
RewriteRule ^index\.php$ /product/category/35/page_%1? [R=301,L]

Resources