Redirect 301 not working using .htaccess - .htaccess

I'm trying redirect a url which has move to another one using 301 redirect. Below is the code which doesn't seems to work:
RewriteEngine On
Redirect /abc/def/ http://my-site.com/ghi/jkl.php
It gives 404 error.

You have to have mod_rewrite installed, and make sure Apache allows .htaccess files.
Install and enable mod_rewrite. Otherwise the RewriteEngine On is not understood by Apache.
sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart
Allow Overrides, otherwise Apache ignores the .htaccess file in your dierctory. In your Apache configuration (probably in /etc/apache2/sites-enabled/your-site.conf or somewhere in /etc/httpd/), make sure that your vhost has not AllowOverride None set. The default is AllowOverride All.

Related

.htaccess file 404 error with parallel plesk server

I have my .htaccess file working in localhost. But its not working if i upload it in server. It throws me 404 error.
I am using Parallel Plesk 11.0.9 and i can't find conf file for the same on that. If anyone has any idea how to fix it or any workaround for url rewriting would be great help.
Anyway here's the code in htaccess:
RewriteEngine on
RewriteRule ^store/living/Hutches-Armoires-Side-tables-Coffee-tables-Entertainment-centers? store.php?store=Living
RewriteRule ^store/dining/sideboards-buffets-chairs-benches-Dining-table$ store.php?store=Dining
RewriteRule ^store/working/Bookshelves-Study-tables$ store.php?store=Working
RewriteRule ^store/accessories/Boxes-Photo-Frames-Mirror-Frames-Block-Stamps-and-Book-stands$ store.php?store=Accessories
RewriteRule ^store/hallway/Console-tables-Armoires$ store.php?store=Hallway
RewriteRule ^store/sleeping/Bed-Frames-Night-Stands-Dressers-Mirror-framesBed-Linens-Canopies-Curtains$ store.php?store=Sleeping
You may need to wrap your rewrite rules with:
<IfModule mod_rewrite.c>
...
</IfModule>
...probably a good idea anyway.
Or you could try putting your rules into a vhost.conf file in the conf directory immediately below the location of your httpdocs directory. For example on a Centos machine the web root might be
/var/www/vhosts/domain.com/httpdocs
and you should have a:
/var/www/vhosts/domain.com/conf
directory, this will contain a set of pregenerated Apache config files that Plesk creates. If there isn't already create a vhost.conf and add your rules between a set of
<Directory /var/www/vhosts/domain.com/httpdocs/ >
... your rules ...
</Directory>
Once you've created the vhost.conf file you will need to tell plesk about it with
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain domain.com
If you still can't get it to work you can add a log for mod_rewrite, see this relevant SO answer for details
Is your Plesk running IIS and supporting PHP via FastCGI or ISAPI? If that is the case, check whether URL Rewrite is installed and follow this guide to translate htaccess (for apache) into web.config (for IIS)

Rewrite subdirectory to index.html

I have a subdirectory setup with a static website inside.
But when I go to www.site.com/directory/ it doesn't show the index page, only www.site.com/directory/index.html works.
Is there a way for .htaccess to rewrite this?
I can't just forward all urls because there are also other pages like www.site.com/directory/other.html that still need to work.
Inside /directory/ it's enough that you put an .htaccess file with the directive:
DirectoryIndex index.html
If it still does not work, maybe there are other server directives conflicting with it.
In Apache config you should enable AllowOverride so you could set different options in .htaccess. In that file you could set the DirectoryIndex directive.
See:
http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryindex
http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride

Redirect links to correct directory

We have on our site hundreds of links that point to:
/about/about/filename.html
But we need them to go to:
/about/filename.html
Is there a way to point them to the correct directory?
We are running on a Linux server and the site is build with Joomla Version 1.5.10 and there is ARTIO JoomSEF 3.8.2 running on it.
Thanks
Assuming you're using the Apache webserver, you can use mod_rewrite, specifically the RewriteRule directive:
RewriteRule /about/about/(.+)$ /about/$1 [R=301]
Place this rule in your httpd.conf file in the <VirtualHost> context for the site in question, or in a .htaccess file in the site's DocumentRoot.
This rule will create a 301 Permanent redirect for requests to any path under /about/about/ to the same path under /about/. e.g., /about/about/filename.html will redirect to /about/filename.html

Apache mod_rewrite works in .htaccess but not httpd.conf

I'm experimenting with mod_rewrite for the first time (I'm a web newbie, but trying to learn). I'm trying to get bob.html to redirect to alice.html (read: URL stays the same, page content is alice.html). Both files are in /var/www/. I'm running Ubuntu 10.10 w/Apache 2.2.16.
Here's what works in the .htaccess file placed in the /var/www/ directory:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^bob.html$ alice.html
</IfModule>
This behaves as expected, but it does not work when moved to the httpd.conf file (just learning best practices w/performance and such). I read somewhere that when using mod_rewrite in httpd.conf file, leading slashes are required, so my httpd.conf file looks like:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/bob.html$ /alice.html
</IfModule>
I also read that /etc/apache2/sites-enabled/000-default needs to have AllowOverride set to All.
<Directory /var/www>
...
AllowOverride All
...
</Directory>
I think that's just for use with .htaccess but I wasn't sure so I just left it in.
With all of these configuration settings, the redirection does not work. I've tested to make sure the file itself is being read (someone suggested httpd.conf isn't used anymore and apache2.conf is used instead) by inserting erroneous code. I've taken a look at a couple other questions/answers but I still cant figure it out.
Edit: It should be noted that I'm using /etc/init.d/apache2 restart after each change to httpd.conf to restart Apache and (hopefully) reload the configuration.
Try wrapping the rewriterules in your httpd.conf file in <Location /></Location> tags. The seems to alter the behavior making it more similar to the .htaccess file.

.htaccess rewrite mode is not working

rewrite script in .htaccess
RewriteEngine on
RewriteRule ^index/page/(.*)$ index.php?page=$1
It works in local machine. but in server it does not work. can any body help me?
Have you verified that the rewrite module is loaded on your server? If the server is running apache you should be able to verify this with
apache2ctl -t -D DUMP_MODULES
and looking for the rewrite_module in the response. (NB: You may need apachectl depending on the machine you are using.)
If it is not loaded you might need to change your server configuration. This is doable (again, depending on the version of apache in use) with a step like
a2enmod rewrite
or ensuring your httpd.conf file contains
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
or by ensuring there's a symbolic link between the rewrite.load file /etc/apache2/mods-enabled and /etc/apache2/mods-available.
Don't forget to restart apache afterwards.

Resources