I've just implemented Pretty URL's, taken from this question: htaccess question.
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /
# Ensure www on all URLs.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=302]
# Ensure we are using HTTPS version of the site.
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302]
RewriteCond %{THE_REQUEST} \s/*(.*?)/index\.php [NC]
RewriteRule ^ %1/ [R=302,L]
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1/ [R=302,L]
# Ensure all URLs have a trailing slash.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^.]*?[^/.]$ %{REQUEST_URI}/ [L,R=302]
# Remove all .php extensions without interfering with .js or .css.
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]
But this has broken my site in a few places. On pages that aren't index.php, I've had to add the complete link such as <script src="https://www.example.com/js/bootstrap.min.js"></script>
instead of just <script src="/js/bootstrap.min.js"></script>
, is this the best fix for that?
On my AJAX code
$.fn.login_user = function () {
var email = $('#login_email').val(),
password = $('#login_password').val(),
remember_me = $('input:checkbox:checked').val();
alert("test: " + email + " " + password);
$.ajax({
type: 'POST',
url: '../php/login.php',
data: {email: email, password: password, remember_me: remember_me},
success: function (response) {
alert(response);
}
});
};
jQuery code is functioning from the same file, I've got an image scroller on the site that's still working, and all navigation on site is working but just not sections like this. This AJAX was working perfectly before implementing the .htaccess to remove .php and add the trailing /, but now it's not even getting to the stage of displaying the alert box. This function is called from some javascript code, in another file which is still working perfectly.
My site directory is like so:
mysite.com - index.php
- communications.php
/php/ all php files here
/js/ all js and jquery files here
/css/ all css files here