I have been banging my head against a wall for a long time trying to figure out how to get rid of the last part of some of the URL's on my site. For example, I would like to rewrite this:-
http://www.mysite.com/335-protective-wrapping&page=prod
to this
http://www.mysite.com/335-protective-wrapping
There are about 2000 URL's with &page=prod at the end of them which I need to remove. Here's some more example URL's
http://www.mysite.com/335-protective-wrapping&page=prod
http://www.mysite.com/455-bubble-bags&page=prod
http://www.mysite.com/150-specialist-tapes&page=prod
I have tried many solutions but haven't come up with anything that works.
Any help would be much appreciated.
Thanks.
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
RewriteRule ^([^&]+)&page=prod$ /$1 [L,R=301]
This should work:
RedirectMatch 301 ^/(.*)&page=prod$ http://www.mysite.com/$1
If you really want to take into account the query part (after the ?) of the source-URI you have to use RewriteCond plus RewriteRule, you cannot just use RewriteRule.
(http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond)
Sorry, anubhava, that wont work for that reason.
Related
1st i have to say: i tried google of course. so many tips about my request - but i dont get it. maybe you can help...
it sounds simple: i want a 301 via .htaccess to a another parameter file
for example:
www.mydomain.tld/ runs without .htaccess to www.mydomain.tld/index.php?de_xyz
but:
what i want is, if you call www.mydomain.tld you get to www.mydomain.tld/index.php?en_xyz
-> ?de to ?en
if i try a simple: Redirect 301 /index.php http://www.mydomain.tld/index.php?xyz i get a redirection error on this side.
i have tried so many ways. dont get it :/
thx for your answer
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} !(^|&)en_xyz(&|$) [NC]
RewriteRule ^/?$ %{REQUEST_URI}?en_xyz [L,QSA,R=302]
Have you tried
RewriteRule ^/?$ /index.php?en_xyz [R=301]
Note that 301 is a permanent redirect so the browser might not re-read your configuration if you redirect to a wrong address by mistake while trying.
If not working you might want to add
RewriteLog "/some/path/rewrite.log"
RewriteLogLevel 3
to your vhosts file if you have access (it might not work in .htaccess) and get the details from log.
By the way I'd prefer handling this in index.php:
header('Location: index.php?en', true, 301);
I don't know much about .htaccess, but I'm trying to help a friend who recently moved his blog to Wordpress.
We need to redirect the OLD archive pages like this:
www.domain.com/2010_04_01_archive.html
www.domain.com/2010_04_02_archive.html
www.domain.com/2010_04_03_archive.html
to NEW archive pages like this:
www.domain.com/2010/04/01
www.domain.com/2010/04/02
www.domain.com/2010/04/03
I've tried everything I can find using htaccess redirect and rewrite, but again, I don't really know what I'm doing with htaccess!
Thanks so much for your help,
Amanda
OK tried this:
Turn mod_rewrite on
RewriteEngine On
RewriteRule ^([0-9]{4})([0-9]{2})([0-9]{2})_archive.html$ /$1/$2/$3 [L,R=301]
in .htaccess in the very top level folder of my site. Still, when I go to http://www.bikermetric.com/2010_04_01_archive.html, it doesn't redirect.
Just tried this too:
RedirectMatch 301 ^/([0-9]{4})([0-9]{2})([0-9]{2})_archive.html$ /$1/$2/$3
Still nothing.
You can use mod_alias or mod_rewrite here. You'll want to stick with using mod_rewrite if you already have rewrite rules (stuff that look like RewriteEngine or RewriteRule):
mod_alias:
RedirectMatch 301 ^/([0-9]{4})_([0-9]{2})_([0-9]{2})_archive.html$ /$1/$2/$3
mod_rewrite:
RewriteEngine On
RewriteRule ^([0-9]{4})_([0-9]{2})_([0-9]{2})_archive.html$ /$1/$2/$3 [L,R=301]
You'd want to add it to the htaccess file in your document root.
As said in the Title,I want that http://www.example.com/contact should show http://www.example.com/contact.php. And important: without redirecting.
Unfortunately my .htaccess Code does not work:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^contact$ contact.php [L]
What could be the reason for this? Please help me out how to fix it :(!
EDIT: SOLVED. Google helped me out.
Adding Options -Multiviews was the Solution. Thanks everyone!
I do believe you have to put the / at the beginning of contact because it's part of the path.
Try this:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^/contact$ contact.php [L]
The only way to make the URL at the top show .php when going to the URL without PHP would be to redirect the browser to it. The easiest way to do that in most apache instances would be:
Redirect permanent /contact http://example.com/contact.php
I'm hoping someone can help with this one. I run a forum written in Perl, and the forum does something to URLs that is causing search engines to create duplicates.
I'm thinking that the best way of handling this is to sort it at the htaccess level.
As an example, the following 4 URLs all go to the same page, but search engines are seeing one entry with three duplicates:
http://www.domain.com/forum/YaBB.pl?num=1234567890
http://www.domain.com/forum/YaBB.pl?num=1234567890/2
http://www.domain.com/forum/YaBB.pl?num=1234567890/19
http://www.domain.com/forum/YaBB.pl?num=1234567890/22
I'm looking get htaccess to redirect anything that has a forward-slash somewhere in the last three characters, to a URL that has the slash and trailing numbers removed. Using the above example:
Redirect 301 /forum/YaBB.pl?num=1234567890/2 to /forum/YaBB.pl?num=1234567890
Alternatively, to re-write URLs from that subdomain to strip "/n" and "/nn"
Anyone have any ideas?
Try this:
RewriteEngine On
RewriteBase /
RewriteRule ^cgi-bin/forum/YaBB\.pl\?num=([0-9]+)/[0-9]+$ cgi-bin/forum/YaBB.pl?num=$1 [R=302,L]
This should work, but let me know if it doesn't :) Also if it works, change the 'R=302' to 'R=301'
Try this rule:
Options +FollowSymLinks +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^num=(\d+)/
RewriteRule ^(cgi-bin/forum/YaBB\.pl)$ /$1?num=%1 [R=301,L]
Tested on local Apache installation -- works fine for me.
I am simply trying to get this URL:
http://foo.com/entry/random-entry-123
to redirect to:
http://foo.com/random-entry-123
The "random-entry-123" is dynamic. Different for each entry.
Any help with this is greatly appreciated!
Assuming no further rewrites are in use, and all links inside /entry/ are to rewritten, then try this:
RewriteEngine on
RewriteBase /
RewriteRule ^/entry/(.+)$ /$1 [L,QSA]
Lose the [L] if there are further rewrites ahead in the file.
Although this has already been answered, it didn't work for me when I had two segments after the first, eg:
http://foo.com/entry/random-segment/random-entry-123
Instead this worked for me and also takes care of 301 redirects:
RedirectMatch 301 /entry/(.*) /$1
Hope this helps.