RewriteRule The requested URL was not found on this server - apache

I have same problem :
url rewriting gives "object not found" error
but I'm using sub-domain and it doesn't work ...
My Original URL :
Http://wiki.example.com/articles/index.php?user=Martin&pass=Cohle
I've placed htaccess file in
"wiki.example.com/htdocs/articles/";
RewriteRule
RewriteEngine On
RewriteRule ^wiki_article/([0-9]+)/([A-Za-z0-9-\+]+)/?$ index.php?user=$1&pass=$2[L]
new url
wiki.example.com/wiki_article/Martin/Cohle/
I get :
Object not found!
The requested URL was not found on this server. If you entered the URL
manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
What I did wrong ?

Related

htaccess rewrite rule, parameter with unicode letters

I have tried to follow many answer in the site, without success.
I am trying to rewrite:
domain.com/articles/<author>
To:
domain.com/articles/index.php?author=<author>
My current rule is:
RewriteRule ^(\w*)$ /articles/index.php?author=$1 [B]
That works with letters or numbers, but not with unicode charachters like א and ".
For א, i am getting the following error:
Object not found!
The requested URL was not found on this server. If you entered the URL
manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.9
And for ":
Access forbidden!
You don't have permission to access the requested object. It is either
read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
localhost Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.9
And i need them both.
EDIT:
After reading #user82217 comment i have tried again (.*) regex, this time with the END flag like this:
RewriteRule (.*) /articles/index.php?author=$1 [END]
Now א case is being interpreted well. But " case still gives the same error (Access Forbidden).
#user82217 has suggested to investigate the log. For the " case the log is:
Cannot map GET /articles/%22 HTTP/1.1 to file
Conclusion:
As #user82217 said in a comment, It appears that under Windows OS an address with " char is considered an illegal file to serve, although the address isn't a file at all.
So i gave up the " case for now. Will glad to hear if there is a way to get around that.
RewriteRule ^(\w*)$ /articles/index.php?author=$1 [B]
If you simply replace your pattern with (.*) then you will get a rewrite-loop (which is your 500 Internal Server Error). You could either make the RewriteRule pattern match everything except slashes:
RewriteRule ^([^/]*)$ /articles/index.php?author=$1 [B,L]
However, from your examples it's not clear where your .htaccess file is located. The above assumes it is in the /articles subdirectory.
Alternatively, you could check the query string and only process the directive if the query string is empty:
RewriteCond %{QUERY_STRING} ^$
RewriteRule (.*) /articles/index.php?author=$1 [B,L]
But " case still gives the same error (Access Forbidden).
UPDATE: Ah, this is probably a more fundamental error and is probably a limitation of the OS (are you using Windows?). The " character is not a valid filename character. Apache is unable to map this to a valid filename which would appear to result in a system generated 403 Forbidden.
For the double quotes issue:
The " character is not a valid filename character like #MrWhite said.
#Deadooshka stated in his comment that it cannot be done in .htaccess context.
I think he is right.
#Deadooshka also said it can be done in the <]VirtualHost[> context. However, in my development server i don't use <]VirtualHost[> context.
So the solution was to put the rewrite rule under the global context of Apache's config file (in my case: C:\xampp\apache\conf\httpd.conf) like this:
# <<< existing line >>>
DocumentRoot "C:/xampp/htdocs"
# <<< existing line >>>
# <<< solution >>>
RewriteEngine on
RewriteRule /articles/(\w*)$ /articles/index.php?author=$1 [B]
# <<< solution >>>

mod_rewrite works on localhost but not when upload into server

I wrote a code to redirect people who ask for foo.html to the page bar.html instead.
my .htaccess file is as below
RewriteEngine on
RewriteRule ^foo.html$ bar.html
It works on localhost.But gets the following error when runs in web server.
HTTP Error 404.0 - Not Found The resource you are looking for has been
removed, had its name changed, or is temporarily unavailable.

Block access to folder and allow only from subdomain

I got a folder called roundcube and also a subdomain called webmail.domain.org. I add this code in .htaccess to block accesing to domain.org/roundcube and allow only on webmail.domain.org.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^webmail\.domain\.org$ [NC]
RewriteRule ^roundcube/$ http://webmail.domain.org [L,NC,R=301]`
Accesing domain.org/roundcube still works and webmail.domain.org gives me this error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, me#domain.org and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
What I'm doing wrong?

The requested URL was not found on this server

I have simple html site. how I can fix the problem 'The requested URL was not found on this server' when user gives wrong URL. for example user type mydomain.com/abc.html and this page is not exist on server, so it will cause an error. how to redirect it on error page to avoid this error.
Create a .htaccess file and add this line.
ErrorDocument 404 /foo.html
This will redirect any 404 error to foo.html

Apache is rewriting to index.php, but does not attach the query string

I am trying to get .htaccess to work in my localhost (I've got Mac OS X 10.5). I enabled .htaccess by following articles like this one. But although now the rewriting is taking place, it is not working correctly. As an example, one of the rewrite rules is:
RewriteRule ^(home|faq|about|contact)$ index.php?section=$1 [QSA,NC]
So when I enter http://localhost/~MyUsername/MyWebsite/home, I should be shown http://localhost/~MyUsername/Mywebsite/index.php?section=home ...but instead, a 404 error occurs, and the error message is "The requested URL /Users/MyUsername/Sites/MyWebsite/index.php was not found on this server."
My guess is that something in my Apache configuration is wrong (the rewrite rule works fine in my online host), but how to solve it is beyond my knowledge. Any ideas? Thanks in advance.
Try the following RewriteRule:
RewriteRule ^/(.*)/(home|faq|about|contact)$ /$1/index.php?section=$2 [QSA,NC]
You can test your rewrite rules here - http://martinmelin.se/rewrite-rule-tester/