Can we rewrite a post method based on the body parameters/values, same like query_string in get method?
ex:
Consider I have a post method where paramname=1.
<form action="/action.jsp">
<input type="text" name="paramname" value="1">
<input type="submit" value="Submit">
</form>
I want to redirect the post method only if paramname=1, if 2, i should not.
Like below for Get
RewriteCond %{QUERY_STRING} ^(.*)paramname=1 [NC]
RewriteRule ^(.*) example.com
Please help.
Thanks,
Murali Manohar M
Related
Default url view looks like this: https://example.com/user.php?page=history
I change it with .htaccess to: https://example.com/user/history/
Problem in navigation bar which I made with radio type form. And it gives me: https://example.com/user/history/?page=history
How to change it? Help pls.
.htaccess
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^user/(\w+)$ /user.php?p=$1
RewriteRule ^user/(\w+)/$ /user.php?p=$1
<form name='page' id='page'>
<input id="history" type="radio" name="page" <?php if ($p == 'history') { ?>checked='checked' <?php } ?> onChange="autoSubmit();" value="history" >
<label for="history">Історія замовлень</label>
<input id="settings" type="radio" name="page" <?php if ($p == 'settings') { ?>checked='checked' <?php } ?>onChange="autoSubmit();" value="settings">
<label for="settings">Налаштування</label>
</form>
<script>
function autoSubmit(){
var formObject=document.forms['page'];
formObject.submit();}
</script>
<?php
$p="";
if(isset($_GET["page"])){
$p=$_GET["page"];
}
?>
Radio type menu needs to be like this:
EDIT: Please try following rules as per shown samples in comments.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:[^/]*)/([^/]*)/?$ user.php?page=$1 [L]
With your shown attempts, please try following htaccess Rules file, make sure your php file(s) and htaccess are in same folder. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Doing external rewrite to friendly url here.
RewriteCond %{THE_REQUEST} \s/(.*)/?\?page=([\w-]+)\s [NC]
RewriteRule ^ /%1/%2 [QSD,R=301,L,NE]
##Doing internal rewrite to php files here.
RewriteRule ^(?:[^/]*)/([^/]*)/?$ user.php?page=$1 [QSA,L]
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ product-detail.php?asin=$1 [NC,L]
i have the above rerwrite rules
http://localhost/fashe-colorlib/B07CNMLF8P
http://localhost/fashe-colorlib/product-detail.php?asin=B07CNMLF8P
the above urls are working though i want to get rid of the following url completely.
http://localhost/fashe-colorlib/product-detail.php?asin=B07CNMLF8P
This is how my link looks like
<a href="/fashe-colorlib/product-detail.php?asin=<?php echo $cat_Asin; ?>">
<a href="/fashe-colorlib/<?php echo $cat_Asin; ?>">
Hi there i am working on SEO friendly URLs here is who my url look alike
http://localhost/richmedia/format/?id=Jazz-Cash-HTML-5-Polite-Billboard
This is the part where i am sending request with get method
<form method="GET" action="format/" target="_blank">
<button class="btn btn-primary btn-block" type="submit" >Preview</button>
<input type="hidden" value="'.$seo_title.'" name="id">
</form>
this is what i write in .htacces file
RewriteEngine On
RewriteRule ^creative-zone$ index.php [NC,L]
RewriteRule ^agencies$ agencies.php [NC,L]
RewriteRule ^advertisers$ advertisers.php [NC,L]
RewriteRule ^about-us$ about.php [NC,L]
RewriteRule ^format/?$ format.php?id=$1 [NC,L]
RewriteRule ^(.*)format/([0-9a-zA-Z_-]+)$ format.php?id=$1 [NC,L]
i want to remove this "?id="section from my url. Every Thing is working fine But this ?id= need to be fixex. Need Help. Thanks in advance.
You want to make sure the application still handles the parameter correctly but the answer is fairly straight forward:
RewriteRule ^([0-9A-Za-z_-])?$ index.php?yourparam=$1 [NC,L]
In other words, look for a string after the root, then convert that to an id on the server side.
However when generating the links you'll need to address the id= 'thing'
Your links might look like
link to stuff
which would then be converted to
?id=my_foo_bar
I have a GET form and the variables passed into the URL are rewritten with .htaccess to for a custom URI for an app to open. My problem is the domain is still passed with the rewrite in front of the URI.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \?form=selection&numbers=([0-9]+) [NC]
RewriteRule (.*) customURI:selection%1 [R,NC,L]
This turns into http://domain.com/customURI:selection"numbers" instead of just customURI:selection"numbers".
I suppose this is not an answer but still a solution.
I turned to JS to take on submit and push to a URL.
<script>
function process()
{
var url="customURI:" + document.getElementById("var1").value + document.getElementById("var2").value;
location.href=url;
return false;
}
</script>
<form onSubmit="return process();">
Selection<select id="va1" name="var1">
<option value="blah0">Blah 0</option>
<option value="blah1">Blah 1</option>
<option value="blah2">Blah 2</option></select>
Numbers<input id="var2" type="text" size="12" name="numbers">
<input type="submit" value="Submit"></form>
For instance I have a file php, index.php with content as below:
<ul>
<li>Menu</li>
<li>How it work</li>
</ul>
And I writed .htaccess as below:
RewriteEngine On
RewriteRule ^menu/?$ menu.php
RewriteRule ^how-it-work/?$ howitwork.php
But if I type localhost/menu or localhost/how-it-work it ok, But I want to see link under Menu and How it work also be writed to /menu and /how-it-work, currently it still menu.php and howitwork.php
Another issue, if I have file product.php?action=view&id=123, how could I use htaccess to change it to this localhost/product/123-name-of-topic/
I code and tested on localhost before make it live.
Thanks!
Sorry i cant understand your question first of all,
the final issue could be solved by using a post method in your form instead of get,
<form action="home.php" method="post">
....
....
</form>
Hope this helps.
If I understood right, here is an example:
MODIFIED
RewriteEngine On
RewriteCond %{REQUEST_URI} ^.*howitwork.*$
RewriteRule .* http://mydomain.com/how-it-work [L,R=301]
RewriteCond %{REQUEST_URI} ^.*menu.*$
RewriteRule .* http://mydomain.com/menu [L,R=301]