I have a problem with creation a redirect 301 through htaccess for pages with parameters.
I want to redirect all pages in one directory to the homepage of another (the new URLs are without parameters and have a different structure so I just want to redirect to the main section)
It means - I have now
http://www.mysite.com/old_directory/page.php?s=12345
etc... and all of them I want to redirect to
http://www.mysite.com/new_directory/
How should I modify this redirect? Its Apache server and Wordpress platform.
If you end the substitution string with just a question mark, it will erase an existing query string. mod_rewrite
RewriteRule ^/old_directory/.* /new_directory/? [R=301,L]
Related
In phpmydirectory framework, I'm trying to redirect old page URL to new page URL using .htaccess 301 redirect.
ex: http://example.com/pages/newurl.html?id=old-friendly-url
Redirect works but at the end of new URL, old friendly URL is concatenated as id.
How can I avoid that?
RewriteRule ^pages\/(.+)\.html$ page.php?id=$1 [L,NC]
Redirect 301 /pages/features.html /pages/ost-to-pst-ost-to-office365-ost-to-exchange-migrator.html?
Redirect 301 /pages/features.html /pages/ost-to-pst-ost-to-office365-ost-to-exchange-migrator.html?
Presumably this is the redirect in question? If it already contains a ? at the end then the query string on the original request should already be getting removed - however, if using a mod_alias Redirect you will end up with a trailing ? on the target URL.
You should use mod_rewrite instead to perform this redirect. Since you are already using mod_rewrite for internal rewrites, this is recommended in order to avoid potential conflicts.
Your original redirect is not checking the query string, so I presume this is not a required - you only need to match the URL-path.
The following redirect should go before your existing internal rewrite:
RewriteRule ^pages/oldurl\.html$ /pages/newurl.html? [R,L]
The trailing ? on the RewriteRule substitution removes the query string from the request. Alternatively, use the QSD flag on Apache 2.4+
i have to redirect one url to another. http://www.abc.com/realestate/ to Redirect to http://www.abc.com/businessfinder/company/4105/Property_Agent/. is it better to change on the codeigniter routes.php or the .htaccess file?
If you know that a URL should be redirected then there is no reason to hand the request to PHP. So, redirecting using the .htaccess file would be preferable.
If you have mod_alias installed then you can use the Redirect directive:
Redirect 301 /realestate/ http://www.abc.com/businessfinder/company/4105/Property_Agent/
You can also use mod_rewrite to jump between places in various ways. E.g.:
RewriteRule ^/realestate/?$ /businessfinder/company/4105/Property_Agent/ [R=301,L]
If that is not possible then you can use CodeIgniter's $this->url->redirect() method. It will send the user to any website you like.
I have pages indexed by Google such as sample.com/product-detail.cfm?id=532323. There are a lot of these pages. These pages no longer exist and I would like to redirect all of them to the home page of our new site. Can anyone suggest how to redirect all of the pages without having to do each one individually?
All of them should go to the home page
Then you can just check for /product-detail.cfm and ignore the id= param in the query string. You can do this with either mod_alias or mod_rewrite by adding these directives in the htaccess file in your document root:
Using mod_alias:
Redirect 301 /product-detail.cfm /
Using mod_rewrite:
RewriteEngine On
RewriteRule ^product-detail.cfm$ / [L,R=301]
I had to adjust some paths on my site and I need to use .htaccess to redirect the items on the chance a user accesses the old url.
For example my old urls (relative) could be:
/old-path/page1.php
/old-path/page2.php
/old-path/page3.php
etc...
I had to change the path (for this example) to new-path and I need to adjust the .htaccess so anyone that comes to any page with .../old-path/... will be redirected to
.../new-path/...
Also, would this satisfy the 301 or would I need to list out each page?
You can use either mod+alias:
Redirect 301 /old-path /new-path
or using mod_rewrite:
RewriteEngine On
RewriteRule ^/?old-path/(.*)$ /new-path/$1 [L,R=301]
These could be in the htaccess file in your document root or in the server/vhost config. If you already have rewrite rules somewhere, you may just want to stick with mod_rewrite because redirecting with mod_alias while using mod_rewrite can sometimes give conflicting results.
Using .htaccess, how can I strip parameters from a url and redirect an entire folder to another location?
For example, I have http://www.webbiscuit.co.uk/News.aspx/11/favicon-competition and I just want to redirect this to http://www.webbiscuit.co.uk/.
I have tried
Redirect 301 /News.aspx http://www.webbiscuit.co.uk/
but that just strips off the News.aspx part, and redirects me to
http://www.webbiscuit.co.uk/11/favicon-competition
How can I strip off the entire file and the slugs?
Using mod_rewrite (the ? may be unnecessary here):
RewriteRule ^News\.aspx(.*) http://www.webbiscuit.co.uk/? [NC,R=301,L]