.htaccess RewriteRule not working in different host - apache

My Current .htaccess rule's example
RewriteRule ^([^/\.]+)-([0-9]+) my_article.php?article_permalink=$1&article_id=$2 [NC,L]
ErrorDocument 404 /404errorpage.php
Output:
https://example.com/my-article-example-1
In my localhost and current host these rules working fine. But in other host
10 day ago when I had changed my hosting the first rules was not working. it's showing 404 page (returns 404).
Today in new host the second rule ErrorDocument not working. It's showing
Not Found
The requested URL was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
Expected output:
for any 404 error show 404errorpage page
Now I can't understand what is the problem.

With your shown samples, please try following htaccess Rules. Please make sure your htaccess rules file, my_articile.php file both are in same folder(root folder). Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^(.*)-(\d+)/?$ /my_article.php?article_permalink=$1&article_id=$2 [QSA,NC,L]
ErrorDocument 404 /404errorpage.php

Related

.htaccess issue when including custom 404 error page

This is my first time using .htaccess and currently my .htaccess file is redirecting to my custom 404 page. This is being handled with the following line in my .htaccess file:
ErrorDocument 404 /404.html
On top of this, I need to rewrite a few urls so that /addition/ points to /includes/addition.html (this is one example). So I add the following:
RewriteEngine On
RewriteRule /addition/ /includes/addition.html
But this then serves me a 500 error when Is hold be getting 404 error. On top of this, when I point to mysite.com/addition/ the browser isn't fetching addition.html from my includes folder.
Would someone please explain to me how to have these two rules working without effecting the other, and correct my secondary rewrite rule?
Danke.
Have it this way in your site root .htaccess:
ErrorDocument 404 /404.html
RewriteEngine On
RewriteRule ^/?([a-z]+)/?$ /includes/$1.html [L,NC]

Domain repeated twice in 404 error page when using htaccess

I am developing a .htaccess file for my site to clean up the urls. I am trying to rename my contact page to make sure its working but I keep getting a 404 error page saying that my url missing. The .htaccess files appears to be working fine but my domain is being repeated in the 404 error page. Here is my .htaccess file so far.
# Turn Rewrite Engine On
RewriteEngine on
# Rewrite for contact.php
RewriteRule ^message$ contact.php [NC,L]
Here is the 404 error
The requested URL /domain.com/domain.com/contact.php was not found
on this server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
My .htaccess file is in the root of my site. It is probably a simple problem but I have been trying all the solutions I could find but to no avail.
What happens is, you are using relative links when rewriting URL. This causes the server to look for /domain.com/domain.com/contact.php.
Use absolute URL in rewrite:
RewriteRule ^message$ /contact.php [NC,L]

Redirect Loop while rewriting URL for a video file

I have a video file whose url is modified by .htaccess
RewriteRule ^videos/([0-9]+)/.*$ cms/support/get.file.php?file_id=$1 [QSA,L]
Now when i load the file
http://web01.agmsdallas.com/videos/966/
I end up with redirect loop and the page fails to load. I have checked by .htaccess rule with others and this appears good. The rule works on a different server. Can any one help what could be wrong. Is there some apache directive which is disabled which is causing this error.
It appears the issue been the welcome.conf file of apache which has
<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>
Once we commented that out, the redirection works just fine.

htaccess Rewrite Error & 404

I've been working on my htaccess file to allow rewritten URL paths and everything works fine on my Localhost but when I upload it to the server and type in the url I get a 404 saying:
The requested URL /** was not found on this server. Additionally,
a 404 Not Found error was encountered while trying to use an
ErrorDocument to handle the request.
I've tried to ask my hosting account support team but they say they can't help with this type of problem. My htaccess code is:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^issue=(.*?)&edition=(.*?)&id=(.*?)&title=(.*?)$
RewriteRule ^article.php$ /article/%1/%2/%3/%4 [L,R]
And an example url is:
http://mywebsite.co.uk/article/1/leeds/1394216062/jupiter-falls-to-tour-with-syron-vanes-and-rdc
Why am I getting the 404 & how can I sort this?
You seem to have written the reverse rule. Try this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^article/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /article.php?issue=$1&edition=$2&id=$3&title=$4 [L,QSA,NC]
This will handle: /article/1/leeds/1394216062/jupiter-falls-to-tour-with-syron-vanes-and-rdc URLs.

htaccess giving error - 404

i have found a solution here, which I am looking for
Creating dynamic URLs in htaccess
so basically I modified the given htaccess code (following code is from solution)
RewriteRule ^products/([A-Za-z0-9-])/?$ /view.php?mode=prod&title=$1
I changed it to fit my needs to
RewriteRule ^blog/([A-Za-z0-9-])/?$ /blog.php?id=$1
but when I visit the url localhost/blog/1 it gives me 404 Error, that's the only line in my .htaccess file, what I am doing wrong?
You say that's the only line in your .htaccess, don't you have this one too (just before yours) ?
RewriteEngine On
you .htaccess should contain at least :
RewriteEngine On
RewriteRule ^blog/([A-Za-z0-9-])/?$ /blog.php?id=$1