ZF2 mime type problems - .htaccess

And happy 2016 ;-)
I'm actually trying to learn ZF2, and I have some problems that I dont' know how to resolve.
First, you have to know that the project is running under vagrant.
I have 2 modules:
Admin
Application
I have a layout for each module.
In the admin layout module, I have some style and JS file:
All this JS and CSS files are in the public folder.
<?= $this
->headLink(array('rel' => 'shortcut icon', 'type' => 'image/vnd.microsoft.icon', 'href' => $this->basePath() . '/img/favicon.ico'))
->prependStylesheet($this->basePath('bower_components/bootstrap/dist/css/bootstrap.min.css'))
->prependStylesheet($this->basePath('bower_components/font-awesome/css/font-awesome.min.css'))
->prependStylesheet($this->basePath('bower_components/Ionicons/css/ionicons.min.css'))
->prependStylesheet($this->basePath('css/AdminLTE.min.css'))
->prependStylesheet($this->basePath('css/skins/skin-blue.min.css'))
; ?>
<?=
$this->inlineScript()
->prependFile($this->basePath('bower_components/jquery/dist/jquery.min.js'))
->prependFile($this->basePath('bower_components/bootstrap/dist/js/bootstrap.min.js'))
->prependFile($this->basePath('js/app.min.js'))
;?>
For some CSS file, I have errors in the browser:
Resource interpreted as Stylesheet but transferred with MIME type
text/html
And for JS, I have problems too:
Bootstrap's JavaScript requires jQuery
I know this JS error, it append when you load boostrap.js before jquery.js.
But here, it's not the case!
I don't know if the problem comes from my layout integration of CSS and JS files, or if I forgot something in the controller, or in the configuration.
May be it's a problem with vagrant too?
I also have a htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
Please, I need some help because i'm lost ;-)
Thanks for any advice/documentation or else.

Related

Refresh page on apache with React doesn't work

I'm trying to use React to create a SPA, but I'm running into problem when trying to reload the page.
Before I continue, I must say I already read these questions this and this. I manageg to made it work, but only for the first url.
For example, I have a blog page containing all the posts, accessed via this url mysite.com/blog. This one works fine, if I refresh the page, everything reloads again.
However, when I try to access a single post using a dynamic url, then the page doesn't work. For example, I have this router setup:
// Definiton
<Route path="/post/:url" component={Post} />
// Link
<NavLink to={"post/" + post.url}>...</NavLink>
// Url on the browser
mysite.com/post/this-is-my-first-post
In this case, it's not working. This is my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
After looking more at the problem, I noticed it's trying to load the main files from a different location. For example, when I'm on the page mysite.com/blog it's loading the .css and .js files from mysite.com.
But when I'm the page mysite.com/post/this-is-my-first-post and I refresh the page, it's trying to load the .css and .js files from the directory mysite.com/blog.
I did what Stuffix told in the answe, to check the url definition and also the config at my apache, but everything is enabled and working, just like the answer says.
Well, after looking at some other projects I have using Angular, I noticed one thing, and it was easier than I tought.
Just had to add the tag base on the head of my index.html.
<base href="/" />
This htaccess worked for me with react and angular
<IfModule mod_rewrite.c>
RewriteEngine on
# -- REDIRECTION to https (optional):
# If you need this, uncomment the next two commands
# RewriteCond %{HTTPS} !on
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# --
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) index.html [NC,L]
</IfModule>
In your <Route />, you're declaring the post route is /post/this-is-my-first-post which is correct.
But in your <NavLink />, you're pointing towards /blog/post/this-is-my-first-post since you've missed a slash.
<NavLink to={"post/" + post.url}>...</NavLink>
| here
Thus leading to a 404.
If this doesn't help, your snippet looks fine so the problem might be on what does post.url returns.
Also, your .htaccess looks fine so I would say you might have missed something in your Apache config like AllowOverride all. See this answer.

Codeigniter url/links with mode rewrite htacess: object not found

I am working on project using codeigniter for the first time with bootstrap 3.
My application and system folder from CI is located outside my 'project.main' folder. Everything works fine until I try to use .htaccess in my project.
I am using an XAMPP server and I already loaded the rewrite module and as well as the AllowOverride All and restarted my server.
My url now looks like this 'http://localhost/project.main/' ..
Now my question is since I already removed the 'index.php', my navbar links in bootstrap was like this
'<a href='<?php echo site_url("pages/view/about"); ?>
but if I click it I am directed to the url
'http://localhost/project.main/pages/view/about' which gives me
Object not found' error page.
But if I use href=' <?php echo site_url("index.php/pages/view/about"); ?> I am routed to the right page.
Which is the right way of doing it? and under my config.php I have this $config['uri_protocol'] = 'REQUEST_URI '; is it necessary that uri_protocol match what is on the .htaccess under RewriteCond %(REQUEST_URI)..?
What i read in github there are two versions of .htaccess.
You didnt mention changing index page to blank inside config.php ? In case of emergency I give you my simple htaccess. It works when moving application and system folders out of public.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Also try to switch uri_protocol option.
Here's the ultimate solution for index.php How to remove "index.php" in codeigniter's path .

.htaccess after multiple get variable css, images, etc. won't load

I have a rewriting rule in my .htaccess and when I use only one get variable everything works great. When I use 2 or 3 get variables only the html is loaded and the css and images etc not.
How can I fix this problem? I have tried base tag but still didn't(maybe doing it wrong)
Here is my code in .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/([0-9]+)?$ car-details.php?model=$1&titel=$2&car_id=$3 [L,QSA]
Here is my code in car-details.php :
if (isset($_GET['model'],$_GET['titel'],$_GET['car_id']) === true ) {
$model= trim ($_GET['model']);
$titel = trim($_GET['titel']);
$car_id = trim($_GET['car_id']);
I have solved the problem by putting this code in HTML head section:
<base href="http://www.mydomain.com/">

mod_rewrite to serve html pages through php script

First of all, I've set my rewrite rule to allow the removal of .html from the URL.
I've also created a php script that I want to serve all of my HTML pages. This way, I can create and link to a simple html page, but it will be handled by my php script.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ /folder/webpage.php?view=webpage_handler&file=$1.html [L]
So instead of linking to www.mysite.com/page.html I link to www.mysite.com/page which allows me to access the page.html through webpage.php
I would also like to be able link to the page.html in some other cases (without removing the .html extension) and still have my webpage.php handle the page view.
I've tried:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ /folder/webpage.php?view=webpage_handler&file=$1.html [L]
RewriteRule ^(.*\.(html))$ /folder/webpage.php?view=webpage_handler&file=$1 [L]
but this does not work like expected. I'm not sure if the second rule is working at all, and I do believe they're conflicting each other... but I don't know how to fix it.
Is there a safe way to allow me to link to both "/page.html" and "/page" and get my expected outcome?
After more trial and error, I've learned that what I had was actually correct. For some reason my "view" variable was getting erased which was causing my script to not function properly.
My $_GET['view'] variable was blank in webpage.php but the $_GET['file'] variable was set like it should.
I changed from
view=webpage_handler
to
view=handle_webpage
That's it. It works fine now. Obviously it was something I did, but I have no clue what.

Creating a redirect in htaccess for incoming requests

how can i redirect all requests coming on
foo.bar.com/some-thing
to be redirected to
foo.bar.com/some-thing-else
also can you please hook me up to some good learning resources for learning htaccess, i am very new to this development stuff.
Regards.
Edit
following is the code i have been trying with (without success)
RewriteRule ^some-thing?$ index.php/some-thing-else [QSA,L]
try something like this :
in the .htaccess put this :
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule ^(.*)-thing?$ index.php?route=$1-thing-else [QSA,L]
in the index php put this for testing :
<?php echo var_dump( $_GET ); ?>
browse to your site ie http://localhost/some-thing or http://localhost/dirty-thing.
hope you can modify this to your exact needs.
It is mod_rewrite Apache module what you should be working with to do such redirects. It's not simple to learn, still very powerful tool. There are multiple tutorials learning it. Try http://www.easymodrewrite.com/ for beginning.

Resources