Redirect RewriteRule htaccess - .htaccess

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; ?>">

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]

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]

how to prevent images and css to be rewrite

I have some questions about htaccess ,
but first of all I want to apologize for my bad English.
I want to ask about RewriteRule .
1.If I want to to change my url extension , for example if I want my url to be mysite.com/file.html but the real url is mysite.com/file.php , how to do that ?
I used this code
RewriteRule ^(.*)\.html$ $1.php [R=301,L]
but when I tried it, I found that .html url redirect to .php
2.when I try to rewrite url from http://mysite.com/file.php?varOne=something&varTwo=somethingelse
to http://mysite.com/file/something/somethingelse/
all css,js and images don't appear bcz the dir changed ,
How can I prevent that ?
Thanks
Have you tried using [L] instead of [R=301,L]?
RewriteRule ^(.*)\.html$ $1.php [L]
And when embedding CSS or images in your html, try to begin with a slash to get the files from the root directory:
<link rel="stylesheet" href="/css/style.css" />
The same with images:
<img src="/images/pic.png" alt="image" />
<img src="/mypic.png" alt="image" />
Add the line:
RewriteCond %{REQUEST_FILENAME} !-f
before all of your RewriteRule lines to prevent redirection for css, js and images.

Resources