How to redirect in apache http - apache

It's still showing venue link and it doesn't redirect to directory-testing. is there any right way to redirecting in apache, on ubuntu.
RewriteRule ^(.*)/venue $1/directory-testing [R=301,L]

Have you actually enabled rewriting with:
RewriteEngine on
You can also check that your .htaccess file is actually being parsed. You can just put a syntax error in it and see if it returns error 500. If it doesn't, then you need to enable it in the <directory> section of your httpd.conf with:
AllowOverride All

Related

RedirectMatch file not found

So, I have in my web root an admin.php file and I want every time someone writes /admin to be redirected to that /admin.php.
I wrote in my htaccess
RedirectMatch 301 ^/admin$ /admin.php
However, I get an error from apache "file not found".
I created an empty /admin folder and it works...
Then I try to have an other (also non existant folder) to redirect to admin.php. So I write
RedirectMatch 301 ^/blah$ /admin.php
and it works...
Finally I delete the admin.php and I have the thing redirected to another .php
RedirectMatch 301 ^/admin$ /index.php
and it works again...
I understand that for some reason apache messes things up when the folder to be redirected from has the same name with the .php
With Rewrite I can do the redirection without any problems but I was wondering if it was also possible with just a Redirect... Maybe I am missing something here...
apache messes things up when the folder to be redirected from has the same name with the .php
This is due to Apache's content negotiation module that runs before mod_rewrite, mod_alias and makes Apache web server match extensions of files. e.g. /file can be in URL but it will serve /file.php.
To fix this behavior disable MultiViews by placing this rule on top of your .htaccess:
Options -MultiViews

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.

How to use Apache .htaccess to redirect to another folder

I want to redirect from an old folder to a new one.
I want to redirect the http://domain.com/old/* urls to http://domain.com/new/*.
I found a question which does exactly that: Redirect folder to another with htaccess
I've tried writing a .htaccess in the document root with only the following code given in the answer to the above question:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/old/(.*)$ /new/$1 [L,NC,R=302]
I've also enabled mod_rewrite in the httpd.conf file. But I still can't get apache to redirect from the old folder to the new folder.
I've also check the apache error logs, and all I get is the following error:
[error] [client x.x.x.x] File does not exist: <documentroot>/old
I would skip using med_rewrite for this and instead use Redirect, if you want everything requested from old to be directed to new.
<Directory />
Redirect permanent /old /new
</Directory>
You could skip permanent (Specifies redirect code) depending on your needs. To be able to use a local URL you however need to run Apache >= 2.2.6.

.htaccess RewriteRule and FallbackResource don't work

I'm testing stuff on localhost, and this is my .htaccess file:
RewriteEngine On
RewriteRule ^login/?$ login.php [NC,L]
FallbackResource error.php
in my root directory (/var/www). It just doesn't work. I've already set the "AllowOverride All" in the configuration file: if I put garbage in .htaccess file I get an internal server error (and not a 404), meaning (I think) that the AllowOverride is set properly.
I get "Module rewrite already enabled" if I give "a2enmod rewrite" and, of course, I restarted apache.
Any suggestion? I don't know where to look.
I had the same problem. I found that this error occured only when I tried to access an address with the .php extension. If for example I tried to access test.mydomain.com/home.php, I would get a 404 error. If, however, I tried to access test.mydomain.com/home.html, I had no problem. So I thought it had to do with php interfering with the redirection.
Turns out I had to comment out the following line in my public_html .htaccess file:
#AddHandler application/x-httpd-php5s .php
After that, I could access files in the webroot folder.

Url masking through htaccess not working

I was trying to setup Lithium Php framework. I followed the documentation for getting started.
I have done this: *"make sure mod_rewrite is enabled, and the AllowOverride directive is set to 'All' on the necessary directories involved. Be sure to restart the server before checking things."*
Rewrite module is enabled. Verified by
apache2ctl -M
I have changed the AllowOverride in /etc/apache2/sites-available/default file.
Now when I go to http://localhost/LithiumTestApp/, the page loads but sans css, js, images etc as the links do not work.
I can't seem to find what I have done wrong.
I'm running Apache2 on Ubuntu 11.10.
Edit: Contents of .htaccess are:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Part of Lithium Framework itself. I haven't changed anything here.
I'd recommend first checking to see if your rewrite is working properly.
I usually set a rewrite log path in my vhost file (or set it in your httpd.conf or apache2.conf, whichever your OS uses).
RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 5
Then do:
tail -f /var/log/apache2/rewrite.log
That will allow you to see the log contents while it's happening and refresh the page and see if everything is in order. I also recommend having a look at your Apache error log to see if there are errors in the request.
Also, make sure your resources folder has write permission.