.htaccess re-directs not working on a new server - .htaccess

I have copied a site that that sits under www.domain.co.uk onto a new, testing server which has the url http://c4034105.myzen.co.uk (ultimately we are going to point www.domain.co.uk at this new version)
I am finding that redirects don't appear to work. Here is part of the .htaccess file
RewriteEngine On
ErrorDocument 404 /error.php
#CONTACT
RewriteRule ^contact$ contact.php [L]
RewriteRule ^contact/$ contact.php [L]
The first 404 redirect is working.
However, when the url http://c4034105.myzen.co.uk/memorials/contact is generated we want it to redirect to http://c4034105.myzen.co.uk/contact but it isn't. When it was under its domain.co.uk it worked fine.
What's wrong please
Thanks

the rules you posted only add the .php extension to http://www.example.com/contact, there's no rule which redirects http://example.com/memorials/contact to http://example.com/contact.
here's one:
RewriteRule ^memorials/contact/?$ /contact [L]

Related

Problem with using Rewriterule in htaccess

With RewriteRule I've always cleaned my URLs as following:
RewriteRule ^page/(.*)$ page.php?urlkey=$1 [QSA]
My new host doesn't allow me to use Options +FollowSymLinks and therefore I cannot use the / anymore. So I've changed my RewriteRule to:
RewriteRule ^page-(.*)$ page.php?urlkey=$1 [QSA]
However, I need to redirect all my former URLs to the new version. I tried doing this using the following rule:
RewriteRule ^page/(.*)$ page-(.*)$ [R=301,L]
This is however not working. I've also tried to just make a Redirect in my .htaccess:
Redirect 301 https://www.example.com/page/urlkey https://www.example.com/page-urlkey
This is also not working.
EDIT
As requested the actual code below:
RewriteEngine on
RewriteRule ^citywalk-(.*)$ citywalk.php?urlkey=$1 [QSA]
RewriteRule ^citywalk/(.*)$ citywalk-(.*)$ [R=301,L]
For example the citywalk The Historical Centre has a urlkey the-historical-centre. The old url is citywalk/the-historical-centre.
To test this specific case and other technique:
Redirect 301 /citywalk/the-historical-centre https://example.com/citywalk-the-historical-centre
By visiting https://example.com/citywalk/the-historical-centre no redirecting takes place (the url stays the same in the browser) and no urlkey is found.

URL rewrite for / causing 500 internal server error

I have a rewite rule that should redirect the index page (/) to a different page so I can deal with all of my content in there. However adding this second rule caused a 500 internal server error and I am not sure why.
This is in my .htaccess file
Its the 3rd line:
RewriteEngine on
RewriteRule ^search/(.*)/?$ search.php?postcode=$1
RewriteRule ^(.*)$ /turnstile.php?goto=home [L]
You have to exclude the destination you are rewriting to.
RewriteRule ^((?!turnstile.php).*)$ /turnstile.php?goto=home [L]

mod_rewrite not working

I'm new to working with .htaccess and I'm having trouble using mod_rewrite for apache.
So basically I have a URL. www.website.com/test/index.php
and I'd like it to be shorter www.website.com/t/index.php
So in my .htaccess file I have these three lines:
RewriteEngine On
RewriteBase /
RewriteRule ^test/(.*) t/$1 [R=301,L]
This works perfectly for directing me to www.website.com/t/index.php but the index.php page wont load and will only display a 404 error. Any help would be greatly apprectiated.
You need to do the shortening of your URL first:
RewriteEngine On
RewriteRule ^test/(.*) t/$1 [R=301,L]
...and then make sure, the new (and nonexisting) URL will get processed:
RewriteRule ^t/(.*) test/$1 [L]
The first rewrite is "external", so it is displayed in client browser address bar, but the second is "internal", so apache only displays results from the new URL in place of the old one w/o any change in clients address bar.

Redirect website with htaccess

RewriteEngine on
RewriteRule (.+) http://newdomain.com/$1 [R=301,L]
I am using Wordpress and this is my htaccess configuration file, everything seems to be working except this one. This URL:
http://olddomain.com/wp-content/uploads/2012/12/abc-1-thumb.jpg
Redirects to:
http://newdomain.com/403.shtml
Instead of:
http://newdomain.com/wp-content/uploads/2012/12/abc-1-thumb.jpg
Examples:
http://mister-gan.com/wp-content/uploads/2011/02/simple-and-clean-2.png
http://ganchinhock.com/wp-content/uploads/2011/02/simple-and-clean-2.png
May I know why?
RewriteEngine on
RewriteRule (.+) http://newdomain.com/$1 [R=301,L]
Redirect 301 http://olddomain.com/wp-content/uploads/2012/12/abc-1-thumb.jpg http://newdomain.com/403.shtml
Upon #Wige's comment and rephrasing your question it seems that there is a permissions problem in one of the subdirectories on the new domain, as 403 is a permissions error.

Hide index.php from web site URL

I'm using htaccess rewrite engine to make urls look nice,
from www.mysite.com/index.php?pag=home to www.mysite.com/pag/home
it works fine with this rule
RewriteRule ^pag/([^/]+)$ index.php?pag=$1 [L,QSA,NC]
but when I go to www.mysite.com it redirects me to www.mysite.com/index.php
is there a way to redirect to www.mysite.com/pag/home?
I tried
redirect 301 /index.php http://www.mysite.com/pag/home
but when i try to go to www.mysite.com the browser gives my "page do not exsist error"
This is the rule that Drupal uses to make it's pretty urls, yours should be extremely similar:
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Your rule only matches on urls that have pag in them, but you're really wanting to hit every url.
the problem was in this redirect rule
redirect 301 /index.htm http://www.mysite.com/index.php

Resources