My request will come like /insights/papers-articles.html?view=papers&p=10&/abcdefgh&indcal=1
When i hit this url, it redirect me to /insights/papers-articles/papers-abcdefgh-3.html
I want indcal parameter so url will be /insights/papers-articles/papers-abcdefgh-10.html?indcal=1
I have used following rules :
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(insights)/(papers-articles)\.html\?view=([^&\s]+)&p=([^&\s]+)&/([^&\s]+)&indcal=([0-9]+) [NC]
RewriteRule ^ /%1/%2/%3-%5-%4.html\?indcal=%6 [R=301,L]
But "indcal" parameter is not comming, Please help.
TIA.
This is complete rules
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(insights)/(papers-articles)\.html\?view=([^&\s]+)&p=([^&\s]+)&/([^&\s]+)$ [NC]
RewriteRule ^ /%1/%2/%3-%5-%4.html? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(insights)/(papers-articles)\.html\?view=([^&\s]+)&p=([^&\s]+)&title=([^&\s]+) [NC]
RewriteRule ^ /%1/%2/%3-%5-%4.html? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(insights)/(papers-articles)\.html\?view=([^&\s]+)&q=([^&\s]+)&/([^&\s]+) [NC]
RewriteRule ^ /%1/%2/%3-%5-%4.html? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(insights)/(papers-articles)\.html\?view=([^&\s]+)&q=([^&\s]+)&title=([^&\s]+) [NC]
RewriteRule ^ /%1/%2/%3-%5-%4.html? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(insights)/(papers-articles)\.html\?p=([^&\s]+)&/([^&\s]+) [NC]
RewriteRule ^ /%1/%2/papers-%4-%3.html? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(insights)/(papers-articles)\.html\?view=([^&\s]+)&p=([^&\s]+)&/([^&\s]+)&indcal=([0-9]+) [NC]
RewriteRule ^ /%1/%2/%3-%5-%4.html\?indcal=%6 [R=301,L]
Last rule is for above query.
Rearrange your rules like this:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(insights)/(papers-articles)\.html\?view=([^&\s]+)&p=([^&\s]+)&/([^&\s]+)&indcal=([0-9]+) [NC]
RewriteRule ^ /%1/%2/%3-%5-%4.html\?indcal=%6 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(insights)/(papers-articles)\.html\?view=([^&\s]+)&p=([^&\s]+)&/([^&\s]+)$ [NC]
RewriteRule ^ /%1/%2/%3-%5-%4.html? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(insights)/(papers-articles)\.html\?view=([^&\s]+)&p=([^&\s]+)&title=([^&\s]+) [NC]
RewriteRule ^ /%1/%2/%3-%5-%4.html? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(insights)/(papers-articles)\.html\?view=([^&\s]+)&q=([^&\s]+)&/([^&\s]+) [NC]
RewriteRule ^ /%1/%2/%3-%5-%4.html? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(insights)/(papers-articles)\.html\?view=([^&\s]+)&q=([^&\s]+)&title=([^&\s]+) [NC]
RewriteRule ^ /%1/%2/%3-%5-%4.html? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(insights)/(papers-articles)\.html\?p=([^&\s]+)&/([^&\s]+) [NC]
RewriteRule ^ /%1/%2/papers-%4-%3.html? [R=301,L]
Related
i just want to know how to combine this two conditional format in one htaccess
SSL Https active Force non-wwwRewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Hide extension
RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
maybe like this?
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
I want to remove www. from start of my URL it tried this :
I have found this work for mydomain.com
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.mydomain\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
If i use mydomain.net.in it doesn't work how to get it done?
RewriteCond %{HTTP_HOST} ^mydomain\.net\.in$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.mydomain\.net\.in)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
I am not sure why you first appending www and then removing try with below, it will work for both.
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
Clear cache beforehand.
I have 2 type of url in my page.
1- http://www.example.com/index.php?id=12
I want always this:
http://www.example.com/12
But for anything else like:
2- http://www.example.com/index.php?id=12&id2=123&asd=qwe&svd=sdf...
I want it with no change:
http://www.example.com/?id=12&id2=123&asd=qwe&svd=sdf...
SO I want only redirect for http://www.example.com/index.php?id=12
I try this
RewriteCond %{THE_REQUEST} ^GET\ /(.*/)?(?:index\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /%1%2? [R=301,L]
it works only for first (http://www.example.com/index.php?id=12)
but for second,it redirect to (http://www.example.com/***)
I read in stackoveflow I must use [QSA,L]
So I try this:
RewriteCond %{THE_REQUEST} ^GET\ /(.*/)?(?:index\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /%1%2? [QSA,L]
But I got 500 error (Internal Server Error)
this is my complete code:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{THE_REQUEST} ^GET\ /(.*/)?(?:index\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /%1%2? [R=301,L]
---EDIT ---
I could do it with this
RewriteRule ^index.php/([^/]+)/?([^/]*) /index.php?id=$1 [NC]
for example www.example.com/123 works!
but www.example.com/index.php?id=123 not redirect to www.example.com/12
To convert http://example.com/index.php?id=foo to http://example.com/foo you can use the following rules in root/.htaccesso :
RewriteEngine on
#1)Redirect "/index.php?id=foo" to "/foo"#
RewriteCond %{THE_REQUEST} /(?:index\.php)?\?id=([^\s&]+)\sHTTP [NC]
RewriteRule ^ /%1? [L,R]
#2)The rule bellow will internally map "/foo" to "/index.php?id=foo"#
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /index.php?id=$1 [L]
[Tested] This works on my apache server.
hello all i have a url like
http://www.domain.com/dash?do=about&w=me
but i would like to make it like
http://www.domain.com/dash/about/me
i have these things in my htaccess file.
RewriteEngine On
RewriteBase /
Options All -Indexes
RewriteCond %{REQUEST_METHOD} POST [NC]
RewriteRule ^ - [L]
ErrorDocument 403 /www.domain.com/error404.php
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.*$ [NC]
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# redirect /profile?eid=1 to /eid/1
RewriteCond %{THE_REQUEST} \s/+profile(?:\.php)?\?(eid)=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
# internally rewrite /eid/1 to /profile.php?eid=1
RewriteRule ^(eid)/(\d+)$ profile.php?$1=$2 [L,QSA,NC]
# redirect /dept?did=1 to /did/1
RewriteCond %{THE_REQUEST} \s/+dept(?:\.php)?\?(did)=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
# internally rewrite /did/1 to /dept.php?did=1
RewriteRule ^(did)/(\d+)$ dept.php?$1=$2 [L,QSA,NC]
# redirect /job-details?job=1 to /job/1
RewriteCond %{THE_REQUEST} \s/+job-details(?:\.php)?\?(job)=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
# internally rewrite /job/1 to /job-details.php?job=1
RewriteRule ^(job)/(\d+)$ job-details.php?$1=$2 [L,QSA,NC]
RewriteCond %{THE_REQUEST} \s/+enterprise\.php\?url=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ enterprise.php?url=$1 [L,QSA]
can any one suggest something to achieve this i have ?do=about&w=me comon everywhere and just need to do it like /about/me after the page.
It is slowly becoming difficult to maintain due to so many rules but here it is:
ErrorDocument 403 /www.domain.com/error404.php
Options All -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} POST [NC]
RewriteRule ^ - [L]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.*$ [NC]
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# redirect /profile?eid=1 to /eid/1
RewriteCond %{THE_REQUEST} \s/+profile(?:\.php)?\?(eid)=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
# internally rewrite /eid/1 to /profile.php?eid=1
RewriteRule ^(eid)/(\d+)$ profile.php?$1=$2 [L,QSA,NC]
# redirect /dept?did=1 to /did/1
RewriteCond %{THE_REQUEST} \s/+dept(?:\.php)?\?(did)=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
# internally rewrite /did/1 to /dept.php?did=1
RewriteRule ^(did)/(\d+)$ dept.php?$1=$2 [L,QSA,NC]
# redirect /job-details?job=1 to /job/1
RewriteCond %{THE_REQUEST} \s/+job-details(?:\.php)?\?(job)=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
# internally rewrite /job/1 to /job-details.php?job=1
RewriteRule ^(job)/(\d+)$ job-details.php?$1=$2 [L,QSA,NC]
RewriteCond %{THE_REQUEST} \s/+enterprise\.php\?url=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
# /dash?do=about&w=me => /dash/about/me
RewriteCond %{THE_REQUEST} \s/+([^?]+)(?:.php)?\?do=([^&\s]+)&w=([^&\s]+)\s [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ $1.php?do=$2&w=$3 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ enterprise.php?url=$1 [L,QSA]
I have URLs like the following:
mysite.com/eng?sentence=dog
and I want to rewrite them as
mysite.com/eng/dog
so I want to replace ?sentence= with a "/"
I have tried all of the following:
RewriteCond %{THE_REQUEST} ^GET\ sentence= [NC]
RewriteRule ^ /%1 [NC,L,NE]
RewriteCond %{THE_REQUEST} ^GET\ \?sentence= [NC]
RewriteRule ^ /%1 [NC,L,NE]
RewriteCond %{THE_REQUEST} ^GET\ \?sentence=([^/?&\s]+) [NC]
RewriteRule ^ /%1 [NC,L,NE]
RewriteCond %{THE_REQUEST} ^GET\s/+\?sentence=([^/?&\s]+) [NC]
RewriteRule ^ /%1 [NC,L,NE]
then I tried accessing the URL:
mysite.com/eng?sentence=cat
but it stays as it is. I assume my regex logic is not correct and the rewrite cond is never satisfied. I always have trouble with regex.
You can use this rule:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(eng)\?sentence=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/? [L,R]
This will redirect http://mysite.com/eng?sentence=dog into http://mysite.com/eng/dog/