I followed the steps outlined here.
I copied and paste the code below in .htaccess file. The .htaccess file is in the same repository that contains my dist folder that I am going to deploy on apache.
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
When I access localhost/dist everything goes fine, since it will use my index.html file and it will automatically redirect to localhost/dist/login. Now if I request directly localhost/dist/login, apache complains and displays The requested URL /dist/login was not found on this server. It seems for me that apache does not picked up my .htaccess settings. Is there something I am doing wrong?
Finally I found a way to solve my problem. Maybe this could help some. I enabled the rewrite mode of Apache and instead of
RewriteRule ^ /index.html,
I wrote
RewriteRule ^ /dist/index.html
and this solved my problem.
Related
I have made an installation in a Linux Debian of MediaWiki version 1.31 with Apache. I installed the installation in the path /var/www/html/wiki. All right, because when I open the browser and put http://<ip_server>/wiki, it correctly enters my MediaWiki installation.
What I now want is to redirect or rewrite http://<ip_server>/wiki to http://<ip_server>/ so that if I put in the browser http://<ip_server>/ it will redirect me to my MediaWiki installation.
Try the Short URLs documentation at https://www.mediawiki.org/wiki/Manual:Short_URL/Apache
Basically, you need to create a file called .htaccess in /var/www/html/ with the following content:
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/w/index.php [L]
And add this line to your LocalSettings.php file:
$wgArticlePath = "/$1";
Note: The documentation suggests that you avoid using short URLs that are on the server root (like http://<ip_server>/) because things get complicated when you have pages named Images, Docs, Extensions, etc.
I am trying to create a zend application at my apache web server and used httpdocs folder instead of public folder for my index.php. When I try to access the controller/action, it always looks at the httpdocs directory for the auth file. But since my controller is located in application/controller, it will throw an error. (I have already set the controller directory in the application.ini).
However when I changed the folder name from httpdocs to public and of course update my vhost.conf file, it works. So there must be some settings that must be set.
Now, I tried the same project and code in my lighttpd server and it is also working there.
Is there any setting/conf that must be set in apache server?
Any feedback will be greatly appreciated!
Thanks in advance
Found my answer here.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I just need rewriting in my .htaccess file under httpdocs directory.
I am trying to get an apache RewriteRule to take a url and return the url + .html
Ex: 'www.domain.com/about' should serve the page 'www.domain.com/about.html'
I have tried numerous solutions from SO already but I believe there are some complications due to the site layout.
I am hosting on Network Solutions, so it's shared hosting, and this is a development site so I currently have the dev.domain.com pointed to /htdocs/dev
Directory Structure
-htdocs
--(contains existing sites files)
--.htaccess
----dev
------(contains dev site files)
------.htaccess
So as you can see there is an existing .htaccess file that maybe doing something and there maybe a subdomain issue, I'm not entirely sure, this is my first time working with Apache.
Here's my existing .htaccess which resides in the /htdocs/dev folder
RewriteEngine On
RewriteBase /dev
RewriteCond %{REQUEST_URI}.html -f [NC]
RewriteRule ^ %{REQUEST_URI}.html [L]
Thanks for the help!
You are instructing Apache to make a file check (-f), but it doesn't know where to look. Just change
RewriteCond %{REQUEST_URI}.html -f [NC]
to
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.html -f [NC]
That way Apache has a fully qualified path from your filesystem's root.
I have been using the Zend Framework for years but have realised some crucial problems with our error handling that we are now fixing.
(I posted a different question here: Why my site is always using the ErrorController for all types of errors irrespective of HTTP Status code? explaining the story there).
My question here is a quick one. What does a common .htaccess file of Zend Framework look like?
According to the latest ZF documentation,
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
However, the above is new to me - can someone explain what it does exactly?
My current .htaccess file has a lot of 301 redirect code but for the purpose of this post I'll only paste the relevant information here:
ErrorDocument 404 http://www.mydomain.com/pagenotfound/
ErrorDocument 503 http://www.mydomain.com/service-unavailable/
RewriteCond %{REQUEST_URI} !^/liveagent
RewriteCond %{REQUEST_URI} !^/blog
RewriteRule !\.(js|ico|gif|GIF|jpg|JPG|jpeg|png|PNG|pdf|css|html|xml|swf|php|mp3|mp4|webm|ogv|f4v|flv|txt|wsdl|css3|ttf|eot|svg|woff)$ index.php
The above has been working fine for us, and basically disallows the "liveagent" and "blog" (Wordpress) directories from running with Zend, but I realise I now need to make the following change:
ErrorDocument 404 definitely has to be removed from the code, as Zend Framework should handle all errors. However, when I remove this, going to a URL like www.mydomain.com/this-does-not-exist.php results in a 404 error standard Apache page - it does not load the ZF or the ErrorController. This is because of the "php" exclusion in the above RewriteRule. I do not simply want to remove this since we sometimes want to be able to access php files on the root, such as a separate "holding.php" file which we use for putting the site on maintenance mode.
What is the standard practice? Should I remove the php extension? However this will not solve other 404's like
www.mydomain.com/this-does-not-exist.css
which is also an exclusion (i.e. CSS) in the above RewriteRule.
Therefore, should I completely change the above to Zend's new code for .htaccess as I mentioned above?
If so, I'm a sort of beginner at htaccess - how can I modify that .htaccess code to allow CSS, JS, video files etc. and the blog and liveagent directories to be excluded from the Zend Framework?
I'd switch to the standard ZF rewrite rules instead of the one you have which uses a long regex to redirect to index.php.
Here is an explanation of what the standard .htaccess rules do:
RewriteCond %{REQUEST_FILENAME} -s [OR] # The request is a regular file with size > 0
RewriteCond %{REQUEST_FILENAME} -l [OR] # The request is to a file that is a symlink
RewriteCond %{REQUEST_FILENAME} -d [OR] # The request is to a directory that exists
# if any of the above conditions are true, then simply handle the request as-is
RewriteRule ^.*$ - [NC,L]
# if none of the above match, then rewrite to index.php
RewriteRule ^.*$ index.php [NC,L]
These default ZF rules don't prevent you from accessing existing php files or any other files that are accessible from your document root. If the file requested exists, then the request for that file is served as is. If the file requested does not exist, then the request is forwarded to index.php
Once the request is forwarded to ZF, if there is no matching route, then the ZF ErrorHandler is called and a 404 page (from ZF) is served.
Using the stock ZF rules won't prevent you from having the desired behavior in your application and server settings, and should be a bit more efficient that the regex you currently have. The only things that will really change is that now requests for files that don't exist will be handled by ZF's error handler and no longer by Apache.
Hopefully that answered your question, if not feel free to comment for clarification.
I'm using the Zend Framework, so I'm bootstrapping into a file called index.php. Naturally, I don't want images to be bootstrapped, so I've added a .htaccess file. Here's what it looks like
/application
/library
/public (this is the root of the site)
/images
/js
.htaccess
index.php
This is what's written in my .htaccess:
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|mp3|mov|css)$ index.php
This is basically saying if it doesn't end in .js / .ico / etc, then send the request to index.php. It works just fine on my localhost, but when I get up to actually putting it online, it doesn't. It just routes everything to index.php, regardless of the ending of the request. When mywebsite.com/images/wizard.gif should just show the picture, it tries to load the images controller, which is not what I want it to do.
What could be going wrong? I know it's reading the .htaccess. Is it reading my regex wrong? Why would one apache server read it wrong, while another reads it correctly? Any help would be great.
Here is my .htaccess if you would like to give it a try:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
Basically it checks to make sure the request is not a directory, symlink or a real file, and then sends it to index.php. Otherwise it will provide direct access to the file/directory