Ok so I have a website that already takes the SEO'd URLs and parses the info so that I can get the content for them on their respective pages.
the code in the htaccess file looks like this:
RewriteCond %{REQUEST_URI} !^/(email)/
RewriteRule ^([A-Za-z0-9-]+)\.html /page.php?seo_title=$1 [L]
RewriteCond %{REQUEST_URI} !^/(email)/
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)\.html /page.php?seo_title=$2&seo_parent=$1 [L]
So now a couple of pages have changed from:
old-parent-name/seo-title.html to new-parent-name/seo-title.html
but when i try to do any type of regular 301 redirect, the URL string ends up like this:
http://www.example.com/new-parent/old-seo-title.html?seo_title=old-seo-title&seo_parent=new-parent
Is there any way to do this so that the Query String does not appear?
thanks in advance.
Try adding this above the rules that you have:
RewriteCond %{REQUEST_URI} !^/(email)/
RewriteRule ^old-parent-name/([A-Za-z0-9-]+)\.html /new-seo-parent/$1.html [L,R=301]
Related
How can I redirect url's ending with catalogue.php, for example
http://www.example.com/catalogue.php
to
http://www.example.com/all
Not affecting url's like http://www.example.com/catalogue.php?title=titleName&page=2
Tried the following code:
RewriteCond %{REQUEST_URI} /catalogue.php
RewriteRule ^(.*)$ www.example.com/all/$1 [R=301,L]
Try this:
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^catalogue\.php$ /all [R=301,L]
You will be redirected only if requesting /catalogue.php, wthout any query string parameters.
If you need to specify them, you can change the first line to something similar to:
RewriteCond %{QUERY_STRING} !title|titleName|page
Here redirect will be done only if none of title, titleName, page parameters specified.
Added
If catalogue.php may be in subfolder, use:
RewriteRule (^|/)catalogue\.php$ /all [R=301,L]
You can read more about regular expressions in order to understand how it works.
I'm running a wordpress installation and want to move specific feeds off-site. I've already got most of the technology down, but here's the problem. I want the following URL:
http://www.csicon.net/g/feed
to redirect to
http://feed.mesr.it/g
But if the URL comes in like this:
http://www.csicon.net/g/feed?noRedirect
I don't want it to redirect but load the original. Any thoughts?
The .htaccess file on http://www.csicon.net/ would contain:
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^\/g\/feed$ http://feed.mesr.it/g [L,R=301]
Note: It has not been tested, but you get the idea.
Later Edit: Also, this can be done in PHP.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)csicon\.net$ [NC]
RewriteCond %{QUERY_STRING} !(^|&)noRedirect [NC]
RewriteRule ^([^/]+)/feed/?$ http://feed.mesr.it/$1 [L,NC,R=302]
i am trying to change the url using htaccess rewrite
i want to change this url
page/details.php?name=abcdef&id=18
to
page/abcdef
Here my sample code for this
RewriteEngine On
RewriteRule ^company/([A-Za-z0-9-]+)/$1 company/details.php?name=$1&id=$2 [R=301,L]
this is not working, and also i was tried many code but not working,please help me to find htaccess code for this url
Thanks advance
This should do what you're after:
RewriteCond %{QUERY_STRING} ^.*name=([a-zA-Z0-9]*).*$
RewriteRule ^page/(.*)$ page/%1? [R=301,L]
Try this one:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^name=(.*)&id=(.*)$
RewriteRule ^page/(.*)$ /page/%1? [R=301,L]
This will check for these 2 parameters in the query string.
I have old site with hundreds URL that look like that:
http:www.domain.com/Contact.asp?Pid=344
http:www.domain.com/Contact.asp?Pid=345
http:www.domain.com/Contact.asp?Pid=346
and so on ...
I need to move all of them permanent to 1 single URL :
http:www.domain.com/contact
I tried this:
RewriteCond %{QUERY_STRING} Contact.asp?Pid=([0-999]+)
RewriteRule ^http://www.domain.com/contact? [L,R=301]
But it doesn't work well.
The old site use ASP. The new site build on Joomla. The domain will be the domain from old site
You're close. You need to use the %{QUERY_STRING} variable like you did, but the var doesn't include the URI-path (the Contact.asp?) part. Also, your RewriteRule is missing a regex pattern. Try:
RewriteCond %{QUERY_STRING} Pid=([0-999]+)
RewriteRule ^/?Contact\.asp$ http://www.domain.com/contact? [L,R=301]
RewriteRule ^Contact.asp?Pid=(\d) /contact? [L]
Are the only pages you have on there the contact pages? You could just 301 the entire directory since they are all moving to one URL.
RewriteEngine on
RewriteBase /
RewriteRule ^/(.*)$ http://www.domain.com/$1 [R=301,L]
I need this logic to work:
I want rewrite this string for users to see
http://mysite.com/index.php?cl=mykeystring
to
http://mysite.com/otherkey/
http://mysite.com/index.php?myvar=test&cl=mykeystring&mysecondvar=morevalue
to
http://mysite.com/otherkey/myvar=test&mysecondvar=morevalue
But when http://mysite.com/otherkey/ is written, so load
http://mysite.com/index.php?cl=mykeystring, but no redirects will be done.
Is it possible? There are no possibility to change anything in codes, but only .htaccess
This logic is nearly realized by this code:
RewriteCond %{QUERY_STRING} ^(.*?)cl=mykeystring(.*?)$ [NC]
RewriteRule ^index.php$ /otherkey/%1%2? [R,L]
RewriteRule ^otherkey/(.*?)$ /index.php?cl=mykeystring&$1
but im getting some not needed amp symbols on first rewrite rule. any solutions?
I think you can do something like this:
RewriteCond %{QUERY_STRING} cl=mykeystring [NC]
RewriteRule ^index.php /otherkey/ [QSA]
Docs here: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html