apache returns 404 even after mod_rewrite - mod-rewrite

I am using apache mod_rewrite for the first time.
I want http://example.com/anything/after/this to be transformed as http://example.com/storage-server/index.php?id=/anything/after/this
I have written following lines to apache's httpd.conf file
RewriteRule ^/(.*) /storage-server/index.php?id=$1
But I am getting 404 message saying that this file doesn't exist. I have enabled the mod_rewrite so that is not issue. I think something is preventing this URL to be rewritten....
any idea???
UPDATE::
All things are solved. All above mentioned settings should be entered into /etc/apache2/sites-enables/000-default file..
SOLVED
UPDATE:::
I have just tried extremely simple rewrite rule. I have created test1.html and test2.html files in my web server root. Then i wrote following rule in my httpd.conf file
RewriteRule ^test1\.html$ test2.html
When i visit test1.html the browser still shows test1.html file instead of test2.html/ Please help.. I am having this trouble since last 3 days... sick of it ..:-(

You write that you want it to redirect to http://example.com/index.php?id=/anything/after/this but you're redirecting to http://example.com/storage-server/index.php?id=/anything/after/this. Could that be it?

ensure that the following line in your Apache's httpd.conf is not commented out
LoadModule rewrite_module modules/mod_rewrite.so

Related

apache2 silent redirection not working as expected

I have a web server using apache2, and I want to silently redirect some pages.
So if an user try to access "http://website.com/test.php", the page at "http://website.com/fool.php" will be used instead. And i need to do that for several pages, not just test.php.
I though I could use the mod_rewrite module for this purpose, but I cant get it working.
I tried adding in apache2.conf, so i could have at least just a redirection for now (not silent):
RewriteEngine on
RewriteRule "^/test.php$" "/fool.php"
or
<Directory "/var/www">
RewriteEngine on
RewriteBase "/var/www"
RewriteRule "^/test.php$" "/fool.php"
</Directory>
This result in the test.php not being redirected at all (it still can be accessed), but also, it breaks my custom 404 and 403 pages with the error "ForbiddenYou don't have permission to access this resource.Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.".
Apache2 is not complaining about the syntax when i restart it.
Setting it in my sites-enabled config leads to the same result.
Note that the goal is not to prevent the direct access to test.php, and the request must result in a 200 success code.
There may be something i do not understand, because searching on the net, it looks like it's the way to achieve this.
You may try an alternative method: use the .htaccess file. (place the file in the root directory of your site)
For example:
RewriteEngine on
RewriteRule ^/test.php$ /fool.php [L]

C:/xampp/htdocs/.htaccess: RewriteRule: bad flag delimiters - XAMPP/Windows

I installed XAMPP on my Windows PC.
I created a simple static pages and created .htaccess file in c:\xampp\htdocs.
.htaccess file content is:
RewriteEngine On
RewriteRule ^about-us$ about-us.php [L]
I am getting 404 for the below page:
http://localhost/mysite/about-us/
Anyone help me to identify whats wrong with the .htaccess file.
It worked when I moved my .htaccess file from htdocs to htdocs/mysite

Codeigniter - 1 project - several domain names and several IP

I have 1 dedicated server.
The server has several IPs.
Some IP are dedicated for one particular domain.
Ip1 = mysite.be
Ip2 = mysite.fr
Ip3 = mysite.com
There is only one project. Each domain goes on the same location
My website is on /var/www/vhosts/mysite.com/httpdocs
For all other domain, i create a symlink.
/var/www/vhosts/mysite.be/httpdocs -> /var/www/vhosts/mysite.com/httpdocs
/var/www/vhosts/mysite.fr/httpdocs -> /var/www/vhosts/mysite.com/httpdocs
...
When I go on mysite.com, all works.
But when i go on mysite.be ... I have an output from codeIgniter :
No input file specified.
I search more information about this error and I see that : https://stackoverflow.com/a/14578219/905867
My .htaccess fil is already well configured... I guess
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|css|js|uploads|modules|public|timthumb\.php|\.htpasswd|google.*\.html|captcha)
RewriteRule ^(.*)$ /index.php?/$1 [L]
The fact that the domain linked with symlink display the error "No input file specified." proves that the symlink is OK and the acl on server are OK too (chown and chmod).
I think it's a little thing, but i don't know what. Anyone has a idea please ?
Some others information :
- I manage my server with plesk 11.0.9 #53
- My domain are "php as FastCGI module". If I use "as Apache Module, there is a blank page instead of error "No input file specified."
It takes me long time but... problem is solved.
No input file specified wasn't a CodeIgniter error but a CGI/FastCGI error...
So I check on my plesk an I saw the domain are "PHP as FastCGI module" instead of "PHP as Apache Module".
But... instead of an error, I have a blank page.
Then I thought about open_basedir restriction. It was configured on "Webspaceroot" instead of "Docroot"... and "abracadabra" it works.
Take care !

getting path error (404) in .htaccess

I am using .htaccess file for redirecting page. I have tried both paths, absolute and relative, but in both the cases I am getting error: URL not found (404).
Please guide me proper way to mention path in .htaccess
RewriteRule ^/abc/([a-zA-Z0-9]+)/?$ /abc.php?tag=$1
You may need to RewriteBase /.
Try adding that just before your RewriteRule, i.e:
RewriteEngine On
RewriteBase /
Also try removing the slash before abc:
RewriteRule ^abc/([a-zA-Z0-9]+)/?$ abc.php?tag=$1
One good way to debug the URL rewriting, is to switch on the rewrite logging.
In Apache 2.2:
RewriteLog file-path.log
RewriteLogLevel 3
The syntax is different for Apache 2.4. Read more here.

url rewrite debian

I just got fresh debian VPS into my hands.
I installed url rewrite and simple things like this does seem to work
RewriteRule ^login$ /login.php
However this doesn't work:
RewriteRule ^cats$ /index.php?cat=cats
Anyone have idea why?
(it works on local xampp server + it worked on shared host I had)
Thanks
First of all make sure that you have mod_rewrite, and it's on. To do so, create an empty Php file, then add <? phpinfo() ?> and diplay it in your browser.
If it's "on" then you can go on.
If it's in a .htaccess file then try with / without the slashes.
RewriteRule ^cats$ /index.php?cat=cats
Or
RewriteRule ^/cats$ /index.php?cat=cats
And if that's not enough:
Two hints:
If you're not in a hosted environment (= if it's your own server and you can modify the virtual hosts, not only the .htaccess files), try to use the RewriteLog directive: it helps you to track down such problems:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)

Resources