301 redirecting a rewritten URL - .htaccess

I'm attempting to redirect some rewritten URL's but while the redirect is working, it is including the original parameter before the rewrite.
e.g. Redirect /used-cars.html http://www.odins.co.uk/our-cars.html
The rewritten URL is based upon the following structure:
http://www.domain.co.uk/pages/index.php?p=used-cars
However, what is happening is this:
http://www.domain.co.uk/our-cars.html?p=used-cars
The .htaccess file is as follows:
Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^odins.co.uk [NC]
RewriteRule ^(.*)$ http://www.odins.co.uk/$1 [L,R=301]
RewriteRule ^([^/]*)\.html$ /pages/index.php?p=$1 [L]
RewriteRule ^news/([^/]*)$ /pages/news/index.php?n=$1 [L]
Redirect /used-cars.html http://www.domain.co.uk/our-cars.html
Any help would be appreciated.
Paul

Related

.htaccess 301 Redirecting old dynamic pages to static page

I looked through some other questions but no solutions seem to work. Here's a quick example of some 13k 301 redirects I must do. Here is one of which:
www.mysite.com/beta/index.php/cataloga/category/index.php?option=com_content&view=article&id=55&Itemid=3
to
www.mysite.com/applications/
So here's what I've tried:
Options +SymLinksIfOwnerMatch -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=55&Itemid=3
RewriteRule ^/beta/index.php/cataloga/category/index.php$ /applications/ [R=301,L]
RewriteRule /applications/ ^Itemid=3 [R=301,L]
RewriteRule ^Itemid=3 /applications/ [R=301,L]
RedirectMatch 301 ^/id=55&Itemid=3/.*$ /applications/
Redirect 301 /beta/index.php?option=com_content&view=article&id=55&Itemid=3 /applications/
EDIT
Here is another sample URL I need to go to /compare/:
/beta/index.php/index.php/products/mysite/index.php/cataloga/category/index.php?option=com_content&view=article&id=37&Itemid=16
To check if Redirects were even working, I tested this and it worked fine:
Redirect 301 /beta/index.php/products/hyperpress /
Try this rule:
Options +SymLinksIfOwnerMatch -Indexes
RewriteEngine On
RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=55&Itemid=3\b
RewriteRule (^|/)index\.php$ /applications/? [R=301,L,NC]
RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=37&Itemid=16\b
RewriteRule (^|/)index\.php$ /compare/? [R=301,L,NC]
Leading slash is not matched in htaccess
? at the end of target URI will strip off query strings

htaccess redirect subfolder

I would like to redirect the url http://intranet/trac/paradox/report/6 to http://cobra.woking/trac/paradox/report/6. trac is a subfolder and paradox is a subfolder. report/6 are params that need to be kept and may change.
In my apache doc root i have
#/opt/html/.htaccess
Redirect 301 / http://intranet/intranet
RewriteEngine On
RewriteRule ^trac/paradox/report/6$ http://cobra.woking/trac/paradox/report/6 [L,R]
I have tried the following which does not work
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^intranet$
RewriteRule (.*) http://cobra.woking/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^intranet$
RewriteRule (.*) http://cobra.woking/$1 [R=301,L]
URL i want to change is http://intranet/trac/paradox/ to http://cobra.woking/trac/paradox/. I have placed .htaccess in the /opt/html/trac/paradox/.htaccess
In the htaccess file of your intranet's document root, add this to the top of the file:
RewriteEngine On
RewriteRule ^trac/paradox/report/6$ http://cobra.woking/trac/paradox/report/6 [L,R]

URL Rewrite a previously rewritten URL - htaccess

OK so... I have the following URL which works on my site:
http://my_domain.net/w/mRD3nKkM
The rewrite for this in the root of my site is:
RewriteRule ^([w])/(\w+)$ res/$1/response.php?id=$2 [L]
Simple stuff and works a treat. Now I want to redirect any traffic that hits that URL unencrypted to go over https, like below:
https://my_domain.net/w/mRD3nKkM
So I put another .htaccess file within the res/w/ folder conatining the following:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} ^/response.php$
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^(.*)$ https://my_domain.net/w/$1 [R,L]
To my miind this should work, but doesn't.
To be clear, I have the following URL rewrite working:
http://my_domain.net/w/mRD3nKkM
and I would like it to look like this:
https://my_domain.net/w/mRD3nKkM
Thanks
You should handle http => https before doing internal forward stuff. Following should work for you:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^w/.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
RewriteRule ^(w)/(\w+)/?$ res/$1/response.php?id=$2 [L,NC]

htaccess redirection help needed

I have a dynamic url domain.com/product/Paper_Bags/Merchandise_Bags_-_Matte_Colors/6_25__X_9_25_/Misty_Grey?7. Which when called need to redirect to domain.com/paper-merchandise-bags-plain-white/
I am using the condition and the rule as
RewriteCond %{QUERY_STRING} (.*)$
RewriteRule ^(.*)/Misty_Grey http://domain.com/paper-merchandise-bags-plain-white/? [R=301,L]
But its not working. Can Someone help me to solve this issue.
If i use RedirectMatch ^(.*)/Misty_Grey http://domain.com/paper-merchandise-bags-plain-white/
Its getting redirected to http://domain.com/paper-merchandise-bags-plain-white/?7
Is there any way to remove the ?7 so tha the querystring will not be visible
Try the following commands,
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com[nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
//301 Redirect Old File
Redirect 301 http://domain.com/product/Paper_Bags/Merchandise_Bags_-_Matte_Colors/6_25__X_9_25_/Misty_Grey?7 http://domain.com/paper-merchandise-bags-plain-white/?

Problem 301 redirect not allowing login in the backend

I am finding some problems in the htaccess of CMS with a 301 redirect.
When trying to solve canonical urls (redirecting site to www.site) I got the problem that I cannot log in in the back end (www.site/admin).
The htaccess condition is:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.site\.co.uk$
RewriteRule (.*) http://www.site.co.uk$1 [R=301,L]
I guess I need to include a expression that allows the URI /admin not to be redirected, but how?
Like this, for example:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !=www.example.co.uk
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule .* http://www.example.co.uk%{REQUEST_URI} [R=301,L]

Resources