unable to load php from interface folder - apache

I am new to Apache and recently my developer passed me the website with htaccess to host on Apache 2.4 running on CentOS 7, the website is running on the Windows laptop but not on the server with the same htaccess.
The webpage works like this, when user hits the url at http://www.example.com, and click on the links, it will load the rest of the files from a folder called interface.
The original htaccess as follow:
RewriteEngine On
#this is for specific users
RewriteBase /v1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /v1/index.php?m=$1 [QSA,NC,L]
ErrorDocument 404 /v1/error.php?=error
However it only load the main page, and the rest will load as follow:
Not Found
The requested URL /example was not found on this server.
I have tried the recommendations on this page Generic htaccess redirect www to non-www
and this page .htaccess for cakephp
and this page Remove .php extension with .htaccess
however all of them not working as what we want.
Any way I can get it to work?

Related

.htaccess skips mod_rewrite and directs to ErrorDocument 404

I have the following .htaccess which works wonderfully on a few websites of mine. However, I have uploaded it to another website (on the same host, different domain) and it is now defaulting to the error 404 page; which is displaying correctly.
Example URL: https://www.example.ca/resources-and-links/documents/
The .htaccess first checks to see if there is a actual .php file with first sub-directory, in the example resources-and-links.php. If it does exists it will serve up that page and break down the rest of the sub-directories into the query strings provided.
If the resources-and-link.php doesn't exsits, it directs it to the content.php to check it against pages in the database and serve it if the url matches one of that in the database. If it doesn't the content.php page shows a custom error 404 page.
This works on a sub-domain of said website https://sub.example.com which runs the cms system I built but not the root domain and as said before; shows the ErrorDocument instead. As well, I've used this same .htaccess on many of my other websites without a problem.
I used PHP to show that mod_rewrite is available so are there any reasons why it would not work on the root domain? Why is it skipping straight to the ErrorDocument and serving /404.php?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/([^/]*)
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^([^/]*)(/([^/]*))?(/([^/]*))?(/([^/]*))?(/([^/]*)) /$1.php?ax=$3&do=$5&third=$7&fourth=$9 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z]*)/(.*)$ /content.php?url=$1/$2 [L]
Options +FollowSymLinks
ErrorDocument 404 /404.php
</IfModule>

Problems redirecting from a 403 using .htaccess (Yourls)

I'm using a php app called Yourls. It's a self-hosted url shortener and it's pretty great, I'm happy with its overall functionality. Due to the nature of its development however there isn't much in the way of support. Let's pretend the base url is af.to, where a shortened url would be af.to/goo that might redirect to whatever url is defined by 'goo'. The problem I'm facing is that if someone goes to af.to, they end up on a 403-Forbidden. I'd rather the client is redirected to a specific url instead. I have already picked up a plugin for Yourls which redirects to a url when a shortlink is not found or mis-typed, but this does not cover the base of af.to
I attempted to put in a 403 redirect in the .htaccess, but that broke the whole yourls script resulting in a 500 server error.
Current .htaccess looks like this:
# BEGIN YOURLS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /yourls-loader.php [L]
</IfModule>
# END YOURLS
Any help on what I need to do?
Thank you.
The RewriteCond blocks tell the RewriteRule to skip existing files / folders. When you go to http://af.to/, the root folder exists : no redirection. The apache server doesn't find any index.html (or index.php) file, isn't allowed to list the content of the folder, give up and returns a 403 Forbidden.
You can create the index.html file to show some content or you can add these lines to redirect to an other url :
# just after RewriteEngine On
RewriteRule ^/$ http://my-compagny.com/ [L,R=301]

RewriteRule for a file in a parent directory

I've got a site set up on an apache server with the desktop site in /public_html and a mobile site /in public_html/mob
I'm trying to set up an .htaccess rewriterule to send users to an index.php file in /public_html if they visit the /mob folder. My current rewrite rule, in the mob subfolder is:
RewriteRule ^(/)?$ ../index.php
I can load up the same file in the mob subdirectory with:
RewriteRule ^(/)?$ index.php
However I can't seem to get the site to load the index.php file from the parent directory (public_html).
When attempting to load http://www.domain.com/mob in a browser I receive:
Bad Request
Your browser sent a request that this server could not understand.
This same rewriterule worked fine on our development server, but doesn't work in our live environment.
The .htaccess file from the /public_html/mob folder is as follows:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(/)?$ ../index.php [L,QSA]
When index.php is reached a mobile device detect script decides whether to load the content from the desktop or mobile site.
Check DOCUMENT_ROOT of your m.domain.com.
If DOCUMENT_ROOT for your m.domain.com is /public_html/mob then you cannot load /public_html/index.php without doing a full redirect (or proxy) to http://domain.com/index.php
Just to clarify any web site cannot access files above its DOCUMENT_ROOT folder level.
If your rule's target starts with a /, that makes it an absolute URI starting from the document root, which I assume would be the public_html folder:
RewriteRule ^(/)?$ /index.php

301 redirect html to index.php file from existing .htaccess file

I trying to create some 301 redirects for a friend. His old site was a static site built with a few html pages.
He got a new site built by a developer and would like me to have his old urls redirected to the equivalent page on his new site. If the new site does not have an equivalent page, he would like to have it redirect to the front page.
The old site only had 9 or 10 pages so writing a line in the .htaccess file for each redirect is not a problem for me.
The problem is I have tried everything possible to get a redirect to work using the .htaccess file created by the developer of his new site, with no luck.
The current .htaccess file contains the following lines
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /~example.com/index.php/$1
I have tried all sorts of stuff found on on this site and on google. for example, I would be happy if I could get this to work
RedirectMatch 301 (.*)\.html$ $ /~example.com/index.php/$1
I tried putting that line above the existing RewriteCond but below the existing RewriteEngine line and also tried putting it at the bottom below all the existing lines, but no go. every example I have found does not work. I keep getting a 404 page no matter what I do.
I am a front end guy with no knowledge of Apache and small knowledge of frameworks outside of Drupal and wordpress but It appears that this site is a custom CMS built with the zend framework. The site has an admin interface for creating new pages but has very little options and definitely no option to create redirects. Any ideas?
oh, one more thing. I know that I am in the web directory because if I remove the index.php file the base url returns a 404.
RewriteEngine on
RedirectMatch 301 /(.*?)\.html$ /~example.com/index.php/$1
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /~example.com/index.php/$1

mod-rewrite to ignore the subdomain

I'm using a mod-rewrite for pretty URLs, meant to run on the domain root. Working fine but now I'm trying to make it run on a subdomain and it keeps giving "500 Internal Server Error".
The subdomain automatically redirects to the folder with that name on my hosting account (sub.domain.com shows the content of domain.com/sub/). Does it fail because this request is already being mod-rewritten automatically or can I simply change something in the htaccess to address the subdomain instead?
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Contact your ISP and check if they are setting the DocumentRoot for the sub domains to the /domain/sub/ directory (it's probable) or alternatively using an internal RewriteRule to direct traffic to that directory (you can see if there's an external rewrite / redirect in place via Chrome or Firefox + firebug, use the developer tools to check the response header, on the network Tab). If they have set the document root you will need to copy or symbolically link ALL the files you want accessible via the sub-domain, to the /domain.com/sub/ directory e.g. the .htaccess, index.php, images, js and css files and sub directories. If they are using an internal rewrite, a quick tweak to your own existing internal rewrite, in the existing .htaccess file, should suffice e.g.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]