.htaccess rewriterule ends up as 404 - apache

I'm trying to do simple redirects in my .htaccess file, but always end up as 404 pages.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^resume$ %{DOCUMENT_ROOT}/Resume.pdf [END,R=301]
RewriteRule ^Resume$ %{DOCUMENT_ROOT}/Resume.pdf [END,R=301]
RewriteRule ^resume.pdf$ %{DOCUMENT_ROOT}/Resume.pdf [END,R=301]
Redirect 301 does not redirect as well.

Try without DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^Resume$ /Resume.pdf [L,R=301]
RewriteRule ^resume(\.pdf)?$ /Resume.pdf [L,R=301]
Because the DOCUMENT_ROOT is added by default, it must not be 2x

Related

.htaccess redirect everything to new domain except one URL to something different

I am 301 redirecting everything from http://something.org/* to https://something.com/* with this code...
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) https://www.something.com/$1 [R=301,L]
</IfModule>
I am trying to add exception that this URL http://something.org/registration/service redirects to http://www.something.com/registration/service (not HTTPS like general rule). Tried this to exclude this url from general rule and it works, but I don't know how to add rule to redirect this exclusion to something else:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/registration/service
RewriteRule (.*) https://www.dewesoft.com/$1 [R=301,L]
</IfModule>
Replace your RewriteCond with this :
RewriteRule ^registration/service http://example.com%{REQUEST_URI} [NE,L,R]

How do I rewrite this url with htaccess / mod_rewrite?

how do I rewrite this url with .htaccess mod_rewrite
http://55.100.10.66:81/var/class/tag?isAjax=true&id=189&key=eJwVxzEOwjAMB&callback=_prototypeJSONPCallback_0
to
http://55.100.10.66:81/index.php/var/class/tag?isAjax=true&id=189&key=eJwVxzEOwjAMB&callback=_prototypeJSONPCallback_0
Amongst a lot of things I tried the below which doesn't work
RewriteRule ^var/class/tag(.*) /index.php/var/class/tag$1 [L,NC,QSA]
Thanks!
This is the solution
RewriteCond %{REQUEST_URI} ^/var/class/tag(.*)
RewriteRule .* index.php [L]
You cannot match QUERY_STRING from RewriteRule. Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(var/class/tag/?)$ /index.php/$1 [L,NC]

how do i get this mod_rewrite to work

I am trying to force a redirect of all request to
http://website.com/
to
http://website.com/2013/04/
doing this
RewriteEngine on
Options +FollowSymlinks
Options -Multiviews
RewriteRule ^2013/03/ index.html
will direct any request from
website.com/2013/03/ to the index.html
but how do I force the redirect to website.com/2013/03/
To make your URL lovely and suitable for search engine ranking.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.html HTTP/
RewriteRule ^index.html$ http://www.yoursite.com/ [R=301,L]
To redirect
redirect 301 /old-page.php http://www.yoursite.com/new-page.php

htaccess redirect ignored with rewriteengine

I have a htaccess question that I think may be so simple (dumb?) that no one has had to ask it before. I converted from using html pages to php and for the most part the following has worked:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+)\.htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]
</IfModule>
There are a couple of exceptions though so I assumed putting:
Redirect 301 /oldpage.htm http://example.com/newpage.php
above the IfMofule... would do the trick but it doesn't. The "Redirect 301" is being ignored unless I remove the rest of the code. Could someone tell me what I'm doing wrong?
TIA.
You're using mod_rewrite and mod_alias together and they are both getting applied to the same URL. You should stick with either mod_rewrite or mod_alias.
mod_rewrite: (remove the Redirect directive)
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^oldpage.htm$ http://example.com/newpage.php [R=301,L]
RewriteRule ^(.+)\.htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]
</IfModule>
mod_alias: (remove everything in the <IfModule mod_rewrite.c> block:
Options +FollowSymlinks
Redirect 301 /oldpage.htm http://example.com/newpage.php
RedirectMatch 301 ^/(.+)\.htm$ /htmlrewrite.php?page=$1
Apache processes mod_rewrite (Rewrite*) first and then mod_alias (Redirect).
Use RewriteCond to prevent /oldpage.htm from processed by mod_rewrite.
RewriteCond %{REQUEST_URI} !^/oldpage\.htm$
RewriteRule ^(.+).htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]
Or use RewriteRule instead of Redirect.
RewriteRule ^oldpage\.htm$ http://example.com/newpage.php [L,R=301]
RewriteRule ^(.+).htm$ /htmlrewrite.php?page=$1 [R=301,NC,L]

How to redirect from home.php to home?

This is my code in the .htaccess:
Options -Multiviews
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^home$ home.php [L]
With this code the url www.example.com/home does work but it doesn't redirect from www.example.com/home.php to www.example.com/home
With this code instead:
Options -Multiviews
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^home$ home.php [R=301,L]
I get this error:
Not Found
The requested URL /var/chroot/home/content/08/236108/html/home.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
How can I redirect from home.php to home and avoid errors ?
Options -Multiviews
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^home$ home.php [L]
RewriteCond %{THE_REQUEST} home\.php
RewriteRule ^home.php$ home [R=301,L]