.htaccess rewrite resulting in 404 error - .htaccess

I am trying to create search engine friendly URLs with the following .htaccess and it is directing to a 404 error page no matter what I try.
This is on a Host Gator shared account, if it makes any difference. The directory is (document root)/blog, the .htaccess file is located in the directory "blog."
Example URL would be http://examplesite.com/blog/category/announcements.Here is the .htaccess file contents:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9]+)/$ index.php?category=$1
Any ideas why this is happening?

RewriteRule ^category/([a-zA-Z0-9]+)/*$ index.php?category=$1 [R=301,L]

Forget the preceeding slash?
RewriteRule ^category/([a-zA-Z0-9]+)/$ /index.php?category=$1

Related

redirect url from htaccess file

I'm trying to bulk redirect my site link like this,I need to remove home from every link and redirect it to root directory as shown below.
example.com/home/hello-world.
example.com/home/tag/world.
to
example.com/hello-world
example.com/tag/world.
I'm using these code
RewriteEngine On
RewriteCond %{REQUEST_URI} (.+)/home(.*)$
RewriteRule ^ %1/ [R=301,L]
Considering that your htaccess rules file have more rules apart from your shown ones, which will take care of handling pages from backend(rewrite), if this is the case then please try following htaccess rules file.
Please these rules at top of your htaccess rules file. Also make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /example.com/
RewriteRule ^home/(.*)$ /$1 [R=301,L]

htaccess 301 redirect with wildcard to a single page

We took over a website with about a kabillion pages in the old site root directory done in htm that need to be retired. I want to do a 301 redirect from the pages to the index.php in the root directory of the new site using a wildcard. An example of the page naming structure follows:
oldpage_dees.htm
oldPage_dat.htm
oldPage_deeudderting.htm
and so on. As stated, I need them redirected to the index.php in the root directory. Going by examples and discussions here I've tried:
RewriteEngine On
RewriteRule ^/oldpage_([\w]*).htm$ /index.php [R=301,L]
but I get a 404 error.
Any suggestions? Thanks in advance!
As .htaccess is directory level configuration file, you don't need to specify forward slash, I think this will do the job:
RewriteEngine On
RewriteRule ^oldpage_([\w]*).htm$ index.php [R=301,L]
Meanwhile, you can use the following .htaccess tester to debug your rewrite rules.

.htaccess Rewrite rules not firing

I am trying to come up with a rewrite rule that will rewrite:
oldurl.com/v11/file.ext to newurl.com/v11/file.ext
On the oldurl server I have put the following in .htaccess inside of the folder v11:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^v11/(.*)$ http://newurl.com/v11/$1 [R=301,L]
But the redirect is not firing at all. What did I do wrong?
When placing .htaccess in the v11 folder, your code should be:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ http://newurl.com/v11/$1 [R=301,L]
Check that the new server is set up to allow .htaccess files to be read at the directory level.
If the .htaccess file worked on the other server, it is most likely a server configuration issue or file owner/permissions problem.

.htacess redirect

This may seem like a basic question, but I am not getting how to do it. Here is the Urls below.
Old Url : http://domain.com/index.php/items/view/item_name
New Url : http://domain.com/index.php/items/details/name/item_name
How do I do a permanent redirect with this set of old and new Urls in htaccess?
Put this code in your DOCUMENT_ROOT's .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(items)/view/(.*)$ /$1/details/name/$2 [NC,L,R=301]
The following worked for me....
upload a .htaccess file to the folder where ur file exists with the following data (it should be on a new line in the htaccess file)
redirect 301 /some_dir/oldpage.htm http://www.newdomain.com/newpage.htm
and from what i read somewhere when you need to do the same for a dynamic page you can use the following
consider the page as
http://www.example.com/page.php?id=13
the redirect would be
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=13$
RewriteRule ^/page.php$ http://www.example.com/newname.htm? [L,R=301]
here is what i got on googling for this
http://www.tamingthebeast.net/articles3/spiders-301-redirect.htm

.htaccess redirect for images from old folder to new folder

I have just moved from Drupal + Wordpress to a site completely built in WordPress.
Duly I have a set of images where the files no longer exist and need to try and keep all the images in the one folder (if possible). Duly I need to send requests for any gif|png|jpg that are for http://www.domain.com/blog/wp-content/uploads/ to http://www.domain.com/wp-content/uploads.
If anyone could help would be appreciated - my .htaccess aint what it once was. Thanks in advance
If you google for "htaccess redirect", the top link is this:
http://www.htaccessredirect.net/
If you use the "301 Redirect Directory" section, you get this code:
//301 Redirect Entire Directory
RedirectMatch 301 /blog/wp-content/uploads/(.*) /wp-content/uploads/$1
As far as I know the target domain should be absolute, so the following might work:
//301 Redirect Entire Directory
RedirectMatch 301 /blog/wp-content/uploads/(.*) http://www.domain.com/wp-content/uploads/$1
Please try this rule in your .htaccess:
RewriteEngine On
RewriteRule ^/blog/wp-content/uploads/(.+)\.(png|gif|jpg)$ wp-content/uploads/$1.$2 [QSA,L]
Try this
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://www.domain.com/blog/wp-content/uploads [NC]
RewriteRule .* http://www.domain.com/wp-content/uploads [NC,L]
You could try and put this
RewriteEngine ON
RewriteRule ^/blog/wp-content/(.*)$ http://newdomain.com/wp-content/$1 [R=301,L]
What I have hated about all the re-write rules and redirect options for .htaccess files is they all rely on hardcoding the path (URI) and/or server for the redirect.
The point of the ".htaccess" files it it should be for the current directory! It could be referenced in a number of different ways, installed on different servers in different locations. So trying it down to a specific location for a simple directory rename is illogical.
The solution is to somehow incorporate the current URI (regardless or where the ".htaccess" location) into the result...
This is my current solution for location independent ".htaccess" redirect for a renamed sub-directory, and even I admit it is not perfect... BUT IT WORKS...
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^OLDdir/.*$ %{REQUEST_URI}::: [C]
RewriteRule ^(.*)/OLDdir/(.*)::: $1/NEWdir/$2 [R,L]

Resources