.htaccess RewriteRule to Custom URI - .htaccess

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>

Related

How to change GET in url from html form?

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]

Htaccess Rewrite Post Method

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

http://localhost/richmedia/format/?id=Jazz-Cash-HTML-5-Polite-Billboard "want to remove ?id= from URL"

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

Cakephp 2.5.4: Redirection url after form submit

I want to submit the form to www.example.com/users/signup but my page is submitting to www.example.com/test/users/signup.
Cakephp is installed in test folder. I have created htaccess inside test folder.
This is my htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ test/ [L]
RewriteRule (.*) test/$1 [L]
RewriteRule ^$ /test/users/signup [L]
RewriteRule users/signup /users/signup [L]
</IfModule>
View:
<?php
echo $this->Form->create('User',array('url'=>array('controller'=>'users','action'=>'signup')), array('id' => 'signup', 'role' => 'form','class'=>'form-signin'));
echo $this->Form->input('User.email',array('type'=>'email','required'=>'required','class'=>'form-control','placeholder'=>'Email'));
echo $this->Form->input('User.password',array('type'=>'password','required'=>'required','class'=>'form-control','placeholder'=>'Password'));
?>
<button type="submit" class="btn btn-lg btn-primary btn-block">Sign up</button>
<?php echo $this -> Form -> end(); ?>
I created the routes:
<?php
Router::connect('/users/signup', array('controller' => 'users', 'action' => 'signup'));
?>
If you want to ask any query please feel free to ask.
/signup is the route I connected in routes.php - it's a "pretty url" so I don't have the default /{controller}/{action} format. If the site is not in a sub-folder, any form I generate with $this->Form->create() POSTs to /signup. However, when in the sub-folder, I can see the page at /signup but all generated URLs include the sub-folder. I want the site to work as though there is no sub-folder and behave as though it's in the root. Setting Configure::write('App.baseUrl, '/'); did the trick.
Solution is: Configure::write('App.baseUrl, '/');

Rewrite url in source code

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]

Resources