I have a requirement for URL rewrite, below is the example URL and it is ajax call will invoke the click event
From
https://www.test.com/load/research/compare?submit=true&Actions=ajax&componentID=1600176192830&alias=test-with-machine&subFeature=%2Ftemplate%2Fcontent%2Fmedia
To
https://www.test.com/learn/research/detail?submit=true&Actions=ajax&componentID=1600176192830&alias=test-with-machine&subFeature=%2Ftemplate%2Fcontent%2Fmedia
I tried multiple ways to handle this but all failed, below is the VHOST entry
#RewriteCond %{QUERY_STRING} ^(.*)submit=true(.*)$
#RewriteCond %{QUERY_STRING} (^|&)submit=([^&]*)(&|$)
#RewriteCond %{QUERY_STRING} ^(.*&)?submit=true?(&|$) [NC]
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^/load/research/^(.*)/$ http://localhost:8080/learn/research/detail? [QSA]
Any help would be appreciated. Thanks
The following URL rewrites working fine
RewriteCond %{QUERY_STRING} ^(.*&)?submit=true?(&.*)?$ [NC]
RewriteRule ^/load/research/(.*)$ http://localhost:8080/learn/research/detail?submit=true%1%2 [P,L]
Related
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]
I am using
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule ^wp-admin/admin-ajax.php(.*)$ dl-file.php?file=$1 [QSA,L]
to protect worpdress files which are called with admin-ajax.php from not logged in users. But this breaks ajax for all visitors - so some things won't work for non registered users.
How could I instead just specify a rewriterule for a specific url, for instance this one:
RewriteRule ^wp-admin/admin-ajax.php?action=ajax_request&fn=download&id=(.*) [QSA,L]
id would be a number for a file.
is there a way to do this with htaccess?
I followed user hakre https://wordpress.stackexchange.com/questions/37144/how-to-protect-uploads-if-user-is-not-logged-in using dl-file.php
Thank you!
AD
You can add another RewriteCond based on %{QUERY_STRING} variable to target a specific URL:
RewriteCond %{QUERY_STRING} (?:^|&)action=ajax_request&fn=download&id= [NC]
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule ^wp-admin/admin-ajax\.php$ dl-file.php?file=$1 [QSA,L]
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.
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.
I would like to redirect to https using mod_rewrite only if certain conditions are met:
If the URL does NOT contain the word 'administrator'
AND the URL DOES contain the string 'xyz' (in any part of the URL, including the querystring)
This does not seem to work:
RewriteCond %{REQUEST_URI} xyz [NC,OR]
RewriteCond %{QUERY_STRING} xyz [NC]
RewriteCond %{REQUEST_URI} !administrator [NC]
ReWriteCond %{HTTPS} != on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [NC,R,L]
Try this rule:
RewriteCond %{THE_REQUEST} !administrator
RewriteCond %{THE_REQUEST} xyz
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Testing the request line in THE_REQUEST is easier as it contains both the path and query. But make sure your xyz is not part of the method or HTTP version.
I ended up using a coding solution as I could not get it to work with mod_rewrite. :(