I'm running into a problem when I try to serve my ember app through Apache. Because the location is set to "history" and not "hash", Apache is trying to load the magic ember routes which don't exist as files. myapp.com/login throws a 404 because there is no login.html.
I've done a bit of scouring and its surprising that there isn't much on this which leads me to believe that not many people deploy ember apps on apache.
So it's suggested I write Apache URL Rewrite rules, but the one's I have tried don't seem to be working.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.html [L]
and
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>
Don't work.
Does anyone have any idea of what to do other than go back to "hash"?
Regards, Clueless person.
You need to route everything to index except the files that exist:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html#$1 [L]
If you can back to hash, you can change the locationType setting it to "hash".
Check it out the next answer:
https://stackoverflow.com/a/28630973/4425050
I had the same problem and I fixed it with that.
Related
I'm running a node application (Ghost Blog) on my shared hosting service (a2hosting) However I'm having an issue where my Home Page has /index.php/ at the end. When I navigate to other pages the index.php is not there, and the site works fine, The issue I'm facing is on the following url: http://blog.gregsithole.com
I looked around on stack overflow and found that the issue may be related to my .htaccess file and I'm not too familiar with how to set that up, but below is what my.htaccess file looks like:
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:2368/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:2368/$1 [P,L]
Please assist as I have been looking around for the past few days, and I haven't found a solution to this problem I'm facing. I've seen various posts on here which are related to CodeIgniter
After some help from my hosting service, I finally fixed the issue.
I altered my .htaccess file and based on the suggestion, I added the following to it:
Options +FollowSymLinks -Indexes
IndexIgnore *
DirectoryIndex
RewriteEngine On
RewriteRule ^$ http://127.0.0.1:2368/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:2368/$1 [P,L]
Okay so I need just a little bit of help, I think i almost have my routing clean but am running into one small issue.
I am trying to setup one server to handle multiple different static sites as well as a cakephp 3 installation.
The root .htaccess has the following
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9][-a-z0-9]+)\.domain\.com(:80)?$ [NC]
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{DOCUMENT_ROOT}/%2 -d
RewriteRule ^(.*) /%2/$1 [E=SUBDOMAIN:%2,L]
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},L]
This works great for routing subdomains to their proper folder
static.domain.com properly goes to /static/index.php
the problem comes when i try to access my cake installation
cake.domain.com ends up routing to cake.domain.com/cake/$1
I really need it to route to cake.domain.com/$1
/cake/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/cake/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(webroot/)?(img|css|js)/(.*)$
RewriteRule ^ index.php [L]
</IfModule>
I will be eternally grateful for any help, i have exhausted google searching and banging my head on the wall.
I am completely open to easier ideas as well
What are the reasons why this specific .htaccess code is not working on my hosting server?
It's working perfectly fine locally, and on many other apache systems. (mod_rewrite is ok with the server)
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine on
RewriteCond %{HTTP_COOKIE} HTTP_IS_RETINA [NC]
RewriteCond %{REQUEST_FILENAME} !#2x
RewriteRule ^(.*)\.(gif|jpg|png)$ $1#2x.$2
# if #2x isn't available fulfill the original request
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)#2x\.(gif|jpg|png)$ $1.$2
</IfModule>
Btw. I'm often running into this problem that locally working .htaccess code isn't compatible on a server and I don't understand why that is.
If you're interested in what I was trying to achieve, please go to:
http://shauninman.com/tmp/retina/
Ok, in my case, the RewriteBase / element solved the issue. I'm leaving it there if somebody ever runs in to this issue for shauninmann retina code.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_COOKIE} HTTP_IS_RETINA [NC]
RewriteCond %{REQUEST_FILENAME} !#2x
RewriteRule ^(.*)\.(gif|jpg|png)$ $1#2x.$2
# if #2x isn't available fulfill the original request
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)#2x\.(gif|jpg|png)$ $1.$2
</IfModule>
How to rewrite /foo-bar to foo-bar.html but /foo/bar to foo--bar.html using mod_rewrite?
In other words, replace all slashes in the request URI with --, then append .html.
I wrote the following code:
RewriteEngine On
RewriteBase /
# Take care of /foo/bar and /foo-foo/bar-bar
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/?$ $1--$2.html [L]
# Take care of /foo, or /foo-bar-baz-whatever-no-slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9-]+)/?$ $1.html [L]
This seems to work on some servers but on mine it seems to mess up the rewrites:
The requested URL /foo.html/bar was not found on this server.
It seems to append the .html too early.
Any ideas on how to fix this, and what is causing it to fail on this particular server?
I'm not sure why your example isn't working. Supplying the apache vesion you are using would help a lot. I was able to replicate the issue with Apache/2.2.14
If you remove the RewriteBase Directive and go with
Apache/2.2.14
RewriteEngine On
# Take care of /foo/bar and /foo-foo/bar-bar
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([a-z0-9-]+)/([a-z0-9-]+)/?$ /$1--$2.html [L]
# Take care of /foo, or /foo-bar-baz-whatever-no-slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([a-z0-9-]+)/?$ /$1.html [L]
you should have better luck.
In the future look turn up your log level for easier debugging of what's going on.
#don't leave this on in production
RewriteLog "/private/var/log/apache2/rewrite.log"
RewriteLogLevel 5
One case where this seems to happen is when MultiViews is enabled, but AcceptPathInfo is set to Off (or Default and the handler doesn't accept path info), and foo.html exists.
Apache notices that your request for /foo/bar doesn't point to a real resource, and maps it to /foo.html with the path info of /bar. Because path info is not allowed, Apache returns a 404 for the request. Likewise, mod_rewrite doesn't perform a rewrite because /foo.html now is an existing file.
The solution for this scenario would be to turn off MultiViews in your .htaccess file:
Options -MultiViews
I've added some extra functionality to my wordpress so that I can visit it with a variable and do extra stuff.
The problem is, when I turn my ugly dynamic link into lovely permlink formatting in the .htaccess file, wordpress overrides it / ignores it. I've heard there's a way to do it, but the ways I try to do it based off what people have said still returns a 404 page regardless. I know that the file its pointing to works.
2 ways ppl say works but I've had no joy with:
1) insert the rules above the #BEGIN wordpress part
2) use add_rewrite_rule() wordpress function somewhere
Has anybody had any success with these methods? or other methods?
Here's what my .htaccess file looks like
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/ref/(.*)$ /index.php?ref=1&sid=$1 [NC]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
In my themes function.php I've also tried adding:
add_rewrite_rule('/ref/(.*)$', 'index.php?ref=1&sid=$matches[1]','top');
With no success.
I've also tried the solutions over # WordPress + mod_rewrite with no joy.
Please help! :)
any ideas?
This works - I just tested it - Note I added an L to the end of the RewriteRule
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/ref/(.*)$ /index.php?ref=1&sid=$1 [NC,L]
#wp
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
a new rule will always override the old ones
try the following
<IfModule mod_rewrite.c>
RewriteEngine On
#wp
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^/ref/(.*)$ /index.php?ref=1&sid=$1 [NC]
</IfModule>
In .htaccess files you have to leave the leading slash in the patterns of the RewriteRule directive away. So try this:
RewriteRule ^ref/(.*)$ index.php?ref=1&sid=$1 [NC]
I wound up doing the following in php since the above solutions seemed to not work. Wordpress rulership over the .htaccess file is supreme:
if(strstr($_SERVER['REQUEST_URI'], '/ref/')) {
And from that have been able to do fairly much the same stuff. A pretty url that translates into something else.