I am working on an Ember 2.6 app and have hit a snag when it comes to refreshing the page. This looks to be a common issue so I have found and updated my .htaccess file as follow:
Options FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
So this works whenever I refresh on a URL like: http://danyuschick.com/projects
However, it does not load whenever I refresh on: http://danyuschick.com/projects/14
Here is my router:
Router.map(function() {
this.route('about');
this.route('blogs');
this.route('projects', function() {
this.route('index', { path: '/' });
this.route('project', { path: '/:project_id' });
});
this.route('error', { path: '*path' });
this.route('loading');
});
And my route defining the model
model(params) {
return this.store.findRecord('projects', params.project_id);
}
I'm not sure where this update would need to take place, htaccess or my router or what.
If you try this, it should work:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
What it does, is check if the the %{REQUEST_FILENAME} is a file with a size, OR is a symlink, OR a directory. If not, it will rewrite the request to index.html
Related
I am new to vue js. I have created a project using vue cli 3.
The URLs generated contain #/ at the end, example http://localhost:8080/vuejs#/
I want to get rid of trailing #/, I have tried mode: "history" in router.js file as well as added .htaccess file in root directory with following code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
but it returns a blank page without any error.
Can anyone please help me
Replace
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
with
FallbackResource /index.html
https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations
So I've got the following code which shows all the files of /guides at the root of my site. I would however also like to show all of the files of /news at the root of my site but I can't figure out how I could do both of these at the same time.
Like this:
example.com/guides/google --> example.com/google
example.com/news/youtube --> example.com/youtube
Simply duplicating the rewrite rule and changing it to /news throws a 403 and seems to mess everything up. Here's my current code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /guides/$1 [L]
Thank you and sorry for the novice question!
You can use:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/guides/$1 -f
RewriteRule ^(.*)/?$ /guides/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/news/$1 -f
RewriteRule ^(.*)/?$ /news/$1 [L]
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.
Every time when I click on an URL I get a 404. That's because the page can't be found. But when I add a question mark right after the .domain the page is found. This was not the problem when I had the website hosted in a subdomain folder. A question mark is required to visit a page and I don't want to have the question mark.
Please see the url: http://www.ankehesselmann.nl/
I'm using StaceyApp
This is my .htaccess
RewriteEngine on
# Some hosts require a rewritebase rule, if so, uncomment the RewriteBase line below. If you are running from a subdirectory, your rewritebase should match the name of the path to where stacey is stored.
ie. if in a folder named 'stacey', RewriteBase /stacey
RewriteBase /stacey
ErrorDocument 404 /404.html
# Rewrite any calls to *.html, *.json, *.xml, *.atom, *.rss, *.rdf or *.txt if a folder matching * exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !public/
RewriteCond %{DOCUMENT_ROOT}/public/$1.$2 !-f
RewriteRule (.+)\.(html|json|xml|atom|rss|rdf|txt)$ $1/ [L]
#Add a trailing slash to directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.)
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ([^/]+)$ $1/ [L]
# Rewrite any calls to /* or /app to the index.php file
RewriteCond %{REQUEST_URI} /app/$
RewriteRule ^app/ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ index.php?$1 [L]
# Rewrite any file calls to the public directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !public/
RewriteRule ^(.+)$ public/$1 [L]
I'm guessing the RewriteBase is set to the wrong folder in your .htaccess
Though I cannot explain why it works with the question mark as you said, I would try setting the RewriteBase correctly.
You have to put the sub-folder (path from domain name until your index-file) if you have any. E.g.:
Website located at: example.com/folder1/sub/
RewriteBase /folder1/sub/
If your website doesn't have a sub-folder:
RewriteBase /
You may try removing the line if you haven't got a sub-folder, but it should not make any problems if set to / (slash).
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]