CSS and JS get lost when I edit htaccess - javascript

I have this wird behaviour on my htaccess:
All the "front" links are working fine, but on the editar_post and editar_usuario, the ones that include the GET parameters, I lose all the CSS and JS files:
RewriteEngine On
###### Admin #####
# Posts
RewriteRule ^listar_posts/?$ listar_posts.php [NC]
RewriteRule ^editar_post/?$ editar_post.php [NC]
RewriteRule ^editar_post/([0-9]+)/?$ editar_post.php?post_id=$1 [NC]
RewriteRule ^nuevoPost/?$ nuevoPost.php [NC]
# Usuarios
RewriteRule ^listar_usuarios/?$ listar_usuarios.php [NC]
RewriteRule ^nuevo_usuario/?$ nuevo_usuario.php [NC]
RewriteRule ^editar_usuario/([0-9]+)/?$ editar_usuario.php?id_usuario=$1 [NC]
RewriteRule ^editar_usuario/?$ editar_usuario.php [NC]
# Login
RewriteRule ^login/?$ login.php [NC]
#Front
RewriteRule ^front/?$ front/index.php [NC]
RewriteRule ^front/([0-9]+)/?$ front/post.php?post_id=$1 [NC]
RewriteRule ^front/tecnologia?$ front/search.php?seccion=Tecnologia [NC]
RewriteRule ^front/marketing?$ front/search.php?seccion=Marketing [NC]
RewriteRule ^front/emprende?$ front/search.php?seccion=Emprende [NC]
RewriteRule ^front/tips?$ front/search.php?seccion=Tips [NC]
Can you please help me?
(also if I put the CSS and JS on absolute paths I lose everything no mather what)

htaccess is working but base href add meta
<head>
<base href="http://www.domain.com/" />
</head>

Related

How to remove html extension from file using htaccess provided by WordPress

I am trying to remove .html from url which aren't posted using WordPress using below code :-
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
And the htaccess provided by WordPress is :-
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
The html file I am trying to remove html extension from is not a post but external file uploaded in c panel, any help would be greatly helpful thanks! embers of divinity

Sections of site not working after modifying .htaccess file

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
Have it like this:
Options +FollowSymLinks
RewriteEngine On
# Ignore anything in js/css folders
RewriteRule ^(js|css)/ - [L,NC]
# Add www and turn on https in same rule
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
# Adding a trailing slash
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301]
# Remove index.php externally
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ %1 [L,R=301,NE]
# remove .php externally
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]
# Remove all .php extensions without interfering with .js or .css.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]
Make sure to completely clear your browser cache before testing this change.

Revoke access to certain pages using 404

Hi I have certain urls which i dont want to access by users but unfortunately can't remove them as they are part of my url. For example i have url like this:
example.com/places (want to revoke access to this page)
example.com/places/in/jaipur/ (location is selected)
example.com/places/restaurants/(want to revoke access to this page)
example.com/places/in/jaipur/restaurants/ (location is selected)
In general I want them to 404 if no location is selected.
Just updated the code in htacess but still urls are accessible:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{THE_REQUEST} \s/+places(/restaurants/)?[?\s] [NC]
RewriteRule ^ - [L,R=404]
</IfModule>
# END WordPress
In your .htaccess file you can do the following:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/places/ [OR]
RewriteCond %{REQUEST_URI} ^/places/restaurants/
RewriteRule ^(.*)$ - [R=404,L]
You can use this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+places(/restaurants/)?[?\s] [NC]
RewriteRule ^ - [L,R=404]

Simulate mod_rewrite using JS/JQUERY/PHP

This is my .htaccess, which am I using to rewrite my URLs:
RewriteEngine on
RewriteRule ^$ /home [L,R=301]
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]
RewriteRule ^([a-z0-9-]+)/?$ /index.php?cat=$1 [L,NC,QSA]
RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/?$ /index.php?cat=$1&product=$2 [L,NC,QSA]
Is it possible to rewrite links like that in JS/JQUERY/PHP? (or, for example, call mod_rewrite externally)

ModRewrite breaking styles and javascript

I'm very unfamiliar with htaccess, so I have no clue how to tackle this weird issue.
I have a domain connected to a different server by setting the nameservers. Then I use htaccess and ModRewrite to link paths to subfolders on my server, using an existing script like this:
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/t/domainfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /t/domainfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteRule ^(/)?$ t/domainfolder/index.php [L]
This works perfectly, but I'd also like (dynamic) non-existing directories to work, like domain.com/user/username. I figured I could do that by adding the following line:
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/t/domainfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^user/(.*)$ /t/domainfolder/app/index.php?user=$1 [L]
RewriteRule ^(.*)$ /t/domainfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteRule ^(/)?$ t/domainfolder/index.php [L]
This does work, but all styles break and only plain HTML is visible. The console outputs the following error:
SyntaxError: Unexpected token '<'
The error points to the < of the doctype on the top of the page, so it looks like it is incorrectly parsing the HTML or something. Any help would be greatly appreciated!
EDIT
my non-working addition seems to break my other domains pointing to this server as well
It seemed you break the RewriteCond and RewriteRule pair, add all these lines:
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/t/domainfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^user/(.*)$ /t/domainfolder/app/index.php?user=$1 [L]

Categories