Apache mod_rewriting not finding any files - apache

OK, so we have a specific set of rewrites that we use on a number of sites due the file structure of our programming. It's never been a problem before until now.
For example, the rewrite:
RewriteRule ^$ Pages/news.php
Instead of directing to http://www.domain.com/wedding-venues-and-caterers-news/Pages/news.php it is redirecting to /path/to/file/public/wedding-venues-and-caterers-news/Pages/news.php and it's 404-ing (/path/to/file being the actual path).
If anyone could shed any light as to why this is happening, or point me in the right direction then I would be eternally grateful.
I am running all of my script and files in a subfolder, there is another .htaccess file in the root folder which I have edited in at the bottom but it doesn't seem to contain anything that could be interfering.
If you require any further information on the server then let me know!
EDIT - Here are all my rewrites as requested.
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^$ Pages/news.php
RewriteRule ^images/([0-9]+)/([0-9]+)/(0|1)/(.*).jpg?$ Classes/Image/timthumb.php?src=http://www.domain.com/wedding-venues-and-caterers-news/images/$4.jpg&h=$1&w=$2&zc=$3
RewriteRule ^([A-Za-z0-9\-]+)/([0-9]+)/([0-9]+)(/)?$ Pages/archives.php?cat_id=$2&page=$3 [NC,L]
RewriteRule ^archives/mon/([0-9]+)/yr/([0-9]+)/([0-9]+)$ Pages/archives.php?mon=$1&yr=$2&page=$3 [NC,L]
RewriteRule ^([A-Za-z0-9\-]+)/([0-9]+)(/)?$ Pages/archives.php?cat_id=$2 [NC,L]
RewriteRule ^archives/mon/([0-9]+)/yr/([0-9]+)(/)?$ Pages/archives.php?mon=$1&yr=$2 [NC,L]
RewriteRule ^([A-Za-z0-9\-]+)/([A-Za-z0-9\-]+)/([0-9]+)(/)?$ Pages/article.php?art_id=$3 [NC,L]
RewriteRule ^wedding-venues-catering-rss(/)?$ rss/rss.php [NC,L]
RewriteRule ^Page-Error(/)?$ Pages/errorPage.php [NC,L]
ErrorDocument 404 http://www.domain.com/wedding-venues-and-caterers-news/Page-Error
ErrorDocument 401 http://www.domain.com/wedding-venues-and-caterers-news/Page-Error
ErrorDocument 403 http://www.domain.com/wedding-venues-and-caterers-news/Page-Error
ErrorDocument 404 http://www.domain.com/wedding-venues-and-caterers-news/Page-Error
ErrorDocument 500 http://www.domain.com/wedding-venues-and-caterers-news/Page-Error
I also tried to reference the rewrites with absolute URL's, this worked of course, but they were just redirecting instead of rewriting as you might expect.
EDIT - This is the other .htaccess file in the root directory, which is part of their existing site.
#Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
<IfModule mod_rewrite.c>
RewriteEngine on
redirect 301 /Cavendish.htm http://www.domain.com/
redirect 301 /grange.htm http://www.domain.com/
redirect 301 /restaurant/index.html http://www.domain.com/
redirect 301 /news/Save-money-by-booking-wedding-venues-in-Middlesex-at-off-peak-times.asp http://www.domain.com/
redirect 301 /news/default.asp http://www.domain.com/
EDIT - I thought this might be relevant.
The 404 error on the rewrite shows this path -
/l/i/domain.com/public/wedding-venues-and-caterers-news/Pages/news.php
But.. if I edit news.php and request SCRIPT_FILENAME it gives me the path..
/services/webpages/l/i/domain.com/public/wedding-venues-and-caterers-news/Pages/news.php
My guess is that something is affecting the default path.
Furthermore I have tried basic rewrites at root level, but these also 404.

Finally the issue has been solved.
As the server is hosted with BT Business I decided to email them to see if they could help.
A guy replied saying he had logged in to the server and modified the .htaccess and it now works fine.
He simply added the subfolder in front of the rewritten URL's.
IE:-
RewriteRule ^$ Pages/news.php
Became: -
RewriteRule ^$ wedding-venues-and-caterers-news/Pages/news.php
I am still unsure why the subdirectory is needed when the .htaccess file is inside that directory, my guess is it is something to do with their server settings.

Related

301 redirect dynamic cgi generated urls using .htaccess

I'm having trouble making sense of this .htaccess file I've inherited at my new job. I'm a graphic designer / marketer learning web development. Our site has a bunch of duplication errors and I want to rename our links and have them 301 redirected.
This is the first part of the .htaccess file:
RewriteEngine Off
RewriteCond %{HTTP_HOST} !^blog.asseenontvhot10.com$ [NC]
RewriteCond %{REQUEST_URI} !/sitemap\.xml
AddType text/html .shtml, .html, .htm
AddHandler server-parsed .shtml, .html, .htm
AddHandler application/x-httpd-php5 .html .htm .shtml
#Options FollowSymLinks Includes -Indexes
From what I understand the first part links our blog to the main site, and I'm not sure what the next line does.
The addtype line and the ones that follow enable .htaccess to read/write those filetypes?
Here is the part that I believe is relevant and what I need to change:
RewriteEngine on
rewritecond %{http_host} ^[^.]+\.[^.]+$ [nc]
rewriterule ^(.*)$ http://www.%{http_host}/$1 [r=301,nc]
RewriteRule default.html /home.html
RewriteRule contact\.html /cgi-bin/commerce.cgi?display=contact
RewriteRule about\.html /cgi-bin/commerce.cgi?display=about
RewriteRule register\.html /cgi-bin/commerce.cgi?register=action
RewriteRule products\.html /cgi-bin/commerce.cgi?listcategories
RewriteRule parent_category/(.*)/(.*)/ /cgi-bin/commerce.cgi?listcategories=action&parent=$1
RewriteRule category/(.*)/(.*)/(.*)\.html /cgi-bin/commerce.cgi?search=action&category=$1&page=$3
RewriteRule category/(.*)/(.*)/ /cgi-bin/commerce.cgi?search=action&category=$1
RewriteRule category/(.*).html /cgi-bin/commerce.cgi?search=action&page=$1
RewriteRule product/(.*)/(.*)/ /cgi-bin/commerce.cgi?preadd=action&key=$1
RewriteRule basket\.html /cgi-bin/commerce.cgi?display=basket
RewriteRule log-in\.html /cgi-bin/commerce.cgi?login
RewriteRule home\.html /cgi-bin/commerce.cgi?display=home
RewriteRule search\.html /cgi-bin/commerce.cgi?display=search
RewriteRule all-items\.html /cgi-bin/commerce.cgi?search
RewriteRule update_user\.html /cgi-bin/commerce.cgi?displayuser=action
RewriteRule order_history\.html /cgi-bin/commerce.cgi?orderhistory
RewriteRule logout\.html /cgi-bin/commerce.cgi?logout
RewriteRule specials\.html /cgi-bin/commerce.cgi?search=action&keywords=nav_specials
I know the first part forces www. and does a 301 redirect, even though I haven't seen this way of accomplishing it on any guide I've read. The first thing I really need to change is making the home page 301 redirect from:
http://www.asseenontvhot10.com/cgi-bin/commerce.cgi?display=home
to
http://www.asseenontvhot10.com/
So far as I can tell the RewriteRule makes this an option but dosn't force it. Will adding [r=301] to the end of the rewriterule work?
I've also read that there is code you need to add for .cgi to work as .php does but I'm totally lost there.
Update:
I tried adding this line to the bottom -
Redirect 301 /cgi-bin/commerce.cgi?display=home /
and I got a 500 error.
2nd Update:
I added this code:
RewriteRule about\.html /cgi-bin/commerce.cgi?display=about
RewriteCond %{QUERY_STRING} ^display=about$
RewriteRule ^cgi-bin/commerce\.cgi$ /about [R=301]
And it 404'd. When I replaced the .htaccess file with the back up and the about page still 404's... Now I'm really at a loss and don't know how to revert the site. I don't even know where the redirect would be stored outside of the htaccess file once it's reverted.
3rd Update: (making progress)
I added this code:
RewriteRule about\.html /cgi-bin/commerce.cgi?display=about
RewriteCond %{QUERY_STRING} ^display=about$
RewriteRule ^cgi-bin/commerce\.cgi$ /about\.html? [R=301]
and I got a redirect loop. It was finally redirecting to about.html which I thought the first rule renamed /cgi-bin/commerce.cgi?display=about to, but it redirected to it over and over again.
The Redirect directive in Apache requires that the redirect destination be a fully qualified URL with a scheme and a URL. So this would work:
Redirect 301 /cgi-bin/commerce.cgi http://www.yourdomain.com/
However, I don't believe that Redirect can check the query string, so in order to only apply this redirect if the query string is "display=home" you will probably have to use mod_rewrite like this:
RewriteCond %{QUERY_STRING} ^display=home$
RewriteRule ^cgi-bin/commerce\.cgi$ / [R=301]
The RewriteCond checks that the query string exactly equals "display=home" and the RewriteRule will only trigger if this condition is met. And in the RewriteRule the [R=301] flag instructs mod_rewrite to redirect the visitor's web browser to the target path, / in this case.
By the way, looking at the existing conditions in your .htaccess file, I can't see how your users are seeing the /cgi-bin/commerce.cgi path in their web browser. All of those RewriteRule directives are for silent rewrites. This means that the user will continue to see the "friendly" URL in their web browser, but in the background Apache will actually find the file located at the /cgi-bin/commerce.cgi path and return the content or result of that file to the user. So your users should already be seeing the friendly version of the URL. If what you are trying to do instead is silently rewrite a request for "/" (site root) so that Apache silently rewrites the path and actually fetches the content in the real file /cgi-bin/commerce.cgi?display=home then you probably want this instead:
RewriteRule ^$ /cgi-bin/commerce.cgi?display=home
This will only match a request for the root directory (with no filename specified) and will silently fetch and return the content which results from calling the commerce.cgi file with a "display=home" parameter.

htaccess seo friendly urls, mod rewrite, redirection

I'm currently trying to make SEO friendly URL's for very specific URL's, not all of them. I've been at this for 48 hours with no luck. My goal is to make http://mydomain.com/index.php?p=g&id=1 look like this; http://mydomain.com/pageone/ - so far I have been able to achieve the redirection thusfar, but it is showing a 404 "The requested URL /pageone/ was not found on this server". My question is how to make it redirect to the virtual directory and not throw a 404.
Please note I want to add a rule for each page id, not a rule that changes everything from index.php?p=g&id=, just each specific link.
Below is my htaccess code:
Options +FollowSymLinks
Options -Multiviews
RewriteOptions MaxRedirects=1
RewriteEngine On
RewriteCond %{QUERY_STRING} ^p=g&id=1$ [NC]
RewriteRule ^index\.php$ /pageone/? [r=301,nc]
Any help with this would be GREATLY appreciated.
You redirected the index.php to /pageone/ but did not define what /pageone/ will actually show. You should add the following line to your .htaccess:
RewriteRule ^pageone/?$ index.php?p=g&id=1 [L]
and remove your rule. If you want to keep both RewriteRules, then add the following lines right after RewriteEngine On:
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

Rewrite rules from Apache .htaccess to lighttpd standard

I'm new to lighttpd and I'm having problems with the .htaccess, I know that it's not the same as Apache and you have to do the changes in lighttpd.conf so I'm trying to do my rewrite rules, but they are not working for some reason...
This is my .htaccess file in Apache and I would like if you can convert it for lighttpd so it works on my server, for index.php to open as /index I tried url.rewrite-once = ( "^index$" => "/index.php" ), but it wasn't working so please if you can convert at least the following and if you have time for the other ones convert them as well. By the way, just to let you know, I enabled mod_rewrite from modules.conf so it's possible to use rewrite rules, but as I said I can't convert them right or I don't know what I'm doing wrong ...
ErrorDocument 404 /error.php
RewriteRule ^index$ /index.php [L]
RewriteRule ^view_news/([^/]*)$ /news.php?id=$1 [L]
ErrorDocument 404 /error.php - NOT SOLVED
RewriteCond %{HTTP_HOST} ^your-site\.com$ NOT SOLVED
RewriteRule ^(.*)$ http://www.your-site.com/$1 [R=301,L] - NOT SOLVED
RewriteRule ^index$ /index.php [L] - SOLVED
RewriteRule ^view_news/([^/]*)$ /news.php?id=$1 [L] - SOLVED

Strange behavior for /index.php/foo

I have a website at http://www.mywebsite.com/~me/ and I want these behaviors:
http://www.mywebsite.com/~me/index.php should redirect to http://www.mywebsite.com/~me/
A URL pointing to something that doesn't exist should redirect to http://www.mywebsite.com/~me/404.php
In looking around for solutions, I found these snippets to include in my httpd.conf file:
Options +FollowSymLinks
DirectoryIndex index.php
RewriteEngine On
RewriteBase /~me/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /~me/index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.mywebsite.com/~me/ [R=301,L]
and
ErrorDocument 404 /~me/404.php
These snippets create behavior 1 just fine, and for the most part behavior 2 as well. However, instead of http://www.mywebsite.com/~me/index.php/foo redirecting to the 404 page, it redirects to http://www.mywebsite.com/~me/index.php.
How would I change these snippets to get the behavior I want?

htaccess 404 redirect problem

htaccess 401 redirect problem
My problem is that my 404 redirect to my index.htm file is not working. The only way I can get it to work is by removing the addtype application line below, but I need this for an included left navigation on the site. Any help would be great thank you.
ErrorDocument 404 /
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} \.(gif|jpg|jpeg|png)$
RewriteRule .* products/noimage.jpg [L]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^cases.com [NC]
RewriteRule ^(.*)$ http://www.cases.com/$1 [L,R=301]
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
# Rewrite Rule for blog.cases.com
RewriteCond %{HTTP_HOST} blog.cases.com$
RewriteCond %{REQUEST_URI} !blog/
RewriteRule ^(.*)$ blog/$1
AddType application/x-httpd-php .html .php .htm
I am not sure but some others had some conflicts using the AddType. Some variations that seemed to work for people are added below. Before trying and changing the AddType, put the complete file name in the 404 redirect.
ErrorDocument 404 /index.htm
EDIT:
I just tried your file, and I can't reproduce your issue. I looked at your hosting company's docs and you have it correct. The one thing I do see them mention is multiple extensions, and then takes you to a place showing the code (below) which you said didn't work
<FilesMatch "\.(php|htm|html)$">
SetHandler application/x-httpd-php
</FilesMatch>
They do show in the documentation the full domain listed and specifically mention "filename of the .html file" as shown below.
Custom Error Messages
Add the following to the .htaccess file:
ErrorDocument 404 http://forexample-domain.com/error.html
After "ErrorDocument", specify the error code, followed by a space, and then the path and filename of the .html file you would like to be displayed when the specified error is generated.
Source: http://support.verio.com/documents/view_article.cfm?doc_id=3624
If those don't work, then it probably is something with your hosting company. doesn't make to much since to me, and even if I tried to reproduce, couldn't. Sorry...