I am using a .htccess file in order to rewrite my URLs. I am using the following rules in my .htaccess files
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^product/([0-9]+)/([A-Za-z0-9+]+)$ /product.php?productid=$1&prodname=$2
The rewrite worked fine.
But when i try to access any other page through relative path which is in all the cases, the URL is not getting redirected properly.
Like in the below example
<form action "something.php" method="post">
<input type="text" name="1" />
<input type="submit" value="submit" />
</form>
When I click on submit, the page that gets loaded is http://mydomain/product/1/something/something.php which does not exist and hence throws a 404 error
I tried using the base tag in the head but this creates problem while I am using page anchors and modal windows. It gets redirected to the index page.
Please let me know if further details are required.
I am fairly new to this. So, could someone please help me with this?
Thanks in Advance,
Kartik
This is a URL resolving issue. See mod_rewrite URL info required for details.
You can either use absolute URL paths or absolute URLs:
<form action="/something.php" method="post">
<form action="http://example.com/something.php" method="post">
Or you change the base URL (see BASE HTML element) so that every relative URL is resolved from that URL and not the current URL:
<base href="/">
<base href="http://example.com/">
The short and easy version of solving this is to absolute-path your URLs - /something.php in the form action, not just 'something.php'.
Related
I enabled SSL on my Prestashop 1.6:
Preferences > General > Enable SSL
Preferences > General > Enable SSL on all pages
In .htaccess I used a following code:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
before
# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
Everything looks fine but in view page source of website still I see:
<a class="button ajax_add_to_cart_button btn btn-default" href="http://www.myeshop.com/cart?add=1&id_product=9&token=2db68311c3192a52b4eca5bc1b2c218f" rel="nofollow" title="Add to cart" data-id-product="9"> <span>Add to cart</span> </a>
A href link in Add to cart button directs to http instead https.
Can you help me please?
Regards
Jan
You should look at the smarty template concerned and seeing if classes or controllers are not overridden.
at least you can correct it, with Javascript with something like :
$(document).ready(function()
{
$('.ajax_add_to_cart_button').each(function() {
var href = $(this).attr('href');
href = href.replace('http:', 'https:');
$(this).attr('href', href);
});
});
But it's only for test mode not in production due to security !!!
please read this thread :
Change all occurrences of "http" to "https" on a wordpress page
I got problem with my .htaccess while i using bootstrap nav tabs `
<ul class="nav nav-tabs" role="tablist">
<li class="active">page1</li>
<li>page2</li>
<li>page3</li>
<li>page4</li>
</ul>
I need to change URL to www.domain.com/index/page1 or page2 ... but when i switching between them URL doesn't changed. And when use my .htaccess file nav tabs stop working. What should i type in a .htaccess file to get this URL or use script which i get ID name to the URL and then use this rewrite rule?
RewriteEngine on
RewriteRule index index.php#pane1 [NC,L]
press Ctrl+U You will find the error
The requested URL /registration/js/jquery.min.js was not found on this server.
it is because of our url may like www.example.com/#tab1 original is working
www.example.com/mydir/#tab1 is not valid, It should be written whole bootstrap css and whole bootstrap path to solve this issue.
I'm using react-router with .htaccess and browserHistory. If I understand it correctly, .htaccess file redirects the url to index.html when user addressed url that is only available from front-end and not available from the server. I copied and pasted the .htaccess rule from https://github.com/ReactTraining/react-router/blob/master/docs/guides/Histories.md and basically it's like below:
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
The problem is that it doesn't use right js file when user enters sub-route. Let say I have two files in var/www - index.html, bundle.js.
Inside of index.html,
<body>
<div id="content" class="content-div"></div>
<script src="bundle.js" ></script>
</body>
Inside of bundle.js,
render((
<Router history={browserHistory}>
<Route path="/" component={AppComponent}>
<Route path="post" component={PostComponent}>
<Route path=":postid" component={PostItemComponent}></Route>
</Route>
</Route>
</Router>
), document.getElementById('content'));
It works okay at main page - example.com. But when I enter example.com/post/1, the browser shows me blank page because it tries to access example.com/post/bundle.js which is not there (I don't even have post folder under var/www).
I could temporarily fix the problem by creating var/www/post folder and place bundle.js file into the folder. But I don't think that's right way to do it. Can someone please guide me how I could fix it, so that it always uses var/www/bundle.js whichever sub-sites user enters?
Use a root-relative path for your script tag:
<body>
<div id="content" class="content-div"></div>
<script src="/bundle.js" ></script>
</body>
I need some simple help with my htaccess file, thank you in advance.
I have a number website URLs, such as:
www.site.com/index.php?page_path=solutions-overview.html
www.site.com/index.php?page_path=solutions-a.html
I want to use the RewriteEngine to change the above links to the following respectively:
www.site.com/solutions/overview
www.site.com/solutions/a
Below is the .htaccess code I am using:
RewriteEngine On
RewriteRule ^solutions/overview index.php?page_path=solutions-overview.html
RewriteRule ^solutions/a index.php?page_path=solutions-a.html
This works, however all of my images, CSS files and JS files no longer load because the page is trying to fetch the wrong URLs. For example "/images/blah.jpg" is instead loading as "/solutions/images/blah.jpg".
How can I modify the htaccess code to prevent relative URLs from changing?
Thank you!
Add this line <BASE href="http://www.yoursitename.com/"> to your page inside the <head> tag as follows:
<head>
<title>Your site title</title>
<BASE href="http://www.yoursitename.com/">
....
</head>
Wonder, I'm bulling a system that I will be able to upload to another hosting with domain just 1 file like: index.php and this file will calling to some other file in another server and print the html he got.
so right now, there is a option to do, when I print:
<img border="0" src="images/logo.jpg" alt="" />
something in the .htaccess or something will now that this image is on:
http://www.masterdomain.com/images/template_1/
?
I tried:
RewriteRule ^images/(.*)$ http://www.masterdomain.com/images/template_1/$1
but it's not working very well,
I need also css so I believe it's the same command.
Thank you all!
Try
RewriteRule ^images/(.*)$ http://www.masterdomain.com/images/template_1/$1 [NC,P]
The P flag will proxy your request to the masterdomain server