301 redirects on WHMCS - php

I have installed WHMCS in a subdirectory, domain.com/whmcs
Now I am moving it into the main domain and I will be using custom pages. However, i don't want to have .PHP extension on the custom pages that I created. Ex. domain.com/page.php
I will need to remove .PHP extensions from specific pages and redirect these pages to non .PHP versions.
I just want to double check if this is the right 301 redirect for the search engines, before i publish it:
RewriteEngine on
RewriteRule ^mypage$ mypage.php [L]
Redirect 301 /mypage.php https: //domain.com/mypage
It works perfectly when i type domain.com/mypage.php redirects to domain.com/mypage But i am not sure if it's the right way to do it for the search engines. Currently i use wordpress in the root domain, so basically, I want to match the same links.
Thanks!

Just use this to redirect xyz.php to xyz:
Redirect 301 /xyz.php /xyz
As far as I know about search engines, its better to use a 302 redirect to avoid a 'permanent' issue.
Make sure that /xyz actually shows a valid page. So that you do not mess up with the search engines due to a simple mistake like that.
In your example, you use both mod_rewrite and mod_alias. One of them is enough.
RewriteCond, RewriteRule... are from mod_rewrite
Redirect, RedirectMatch... are from mod_alias
Always, test it once before working on a production server.

Related

How to properly redirect all files inside directory with .htaccess?

I have basically two questions.
How do I redirect domain.com/ipc/ to domain.com/category/indexpage/? Also, what happens to http or https version and www or non www version? Are they all redirected without any problem?
Let's say I want to also redirect domain.com/ipc/page to domain.com/category/indexpage/page? I mean are all webpages inside the directory redirected properly? Is it also possible with .htaccess redirection?
Thanks.
You can use mod_alias for a simple redirect inside your .htaccess file.
RedirectMatch 301 ^/ipc/(.*)$ /category/indexpage/$1
Also this has no baring on whether it was called with http(s) or www/non www. It just handles the redirect regardless.

Ultimate SEO Module + htaccess 301 .html redirect issue

I have successfully installed the Ultimate_SEO_URLs_v2.103 to my shopping cart installation (which is v1.36).
We are getting ready to go live with the site but I need to redirect html pages that are indexed by google to the new html page names.
The problem that I am having is trying to redirect pages with .html extensions to the page names that are rewritten by the htaccess file fromUltimate SEO URL.
It works if I use .htm page for the original page and redirect to the new counterpart page.
Here is the code I am using in .htaccess file (after Ultimate SEO rewrite code):
redirect 301 /old_conditions.html domain.com/conditions.html
so if you go to http://domain.com/old_conditions.html I want it to redirect to http://domain.com/conditions.html
It doesn't work, it goes to the page can not be found page!
Can someone please help me figure out why I can't get a redirect from a .html page when using the Ultimate SEO URL module?
Thanks in Advance!
You can use this rule in your root .htaccess using RewriteRule directive:
RewriteRule ^44-wholesale-celosia\.html$ /flowers/celosia.html [L,NC,R=301]
Also make sure this rule is right at top just below RewriteBase / line.

.HTACCESS - redirect www.example.com/side.php?id=* to www.example.com

I have recently assisted in moving a website from a pure development domain to a live site where there used to be a site handled by another CMS system than what we are currently using. Current system is Joomla, but I don't think it matters much for my question.
So with the current site the URLs are rewritten from the standard Joomla format to be stripped of index.php and .html suffix is added in the address, meaning that URLs look like this:
http://example.com/folder/page.html
In the old site handled by another CMS systems the URLs had the following structure:
http://example.com/side.php?id=1
We are a social organisation with many sites linking to us - also quite a few that we are not even aware of - so the problem I need to handle is this: I need to redirect all these dead links on other sites so that they simply get pointed to the root of our site.
Can anyone please explain to me how to make .htaccess redirect as follows:
/side.php?id=* to root of example.com
In this case I mean the * to mean any number as there are naturally alot of pages with different IDs.
It is not of any significance to me if they point at a www. prefix or not.
Thanks in advance for your help, I hope I have not asked a question that's been answered before but my experience with .htaccess is very limited and having searched and tried different solutions didn't do it for me.
In .htaccess in the root folder, add the following:
RewriteEngine on
RewriteCond %{QUERY_STRING} id=\d+
RewriteRule ^side\.php$ http://%{SERVER_NAME}/ [R=301,L,QSD] #Remove the ",QSD" for Apache <2.4.0, or to keep the query string.
The R=301 will tell browsers/search engines that the page has permanently been moved.
A rule like this should work:
RewriteCond %{HTTP_HOST} .*
RewriteCond %{QUERY_STRING} id=\d+
RewriteRule ^side.php http://example.com [L,R=301]
This will redirect externally, with a HTTP 301 response (Moved Permanently)
What you need here is some 301 Moved Permanently responses to let browsers and search engines know that you're moving pages to a new location. Instead of using a mod_rewrite to redirect all requests to this side.php page, I would analyze each page of your old website and determine where all the content has been moved. Armed with this, use the htaccess Rewrite directive to inform browsers of individual pages being moved
Redirect 301 /side.php?id=123 /about_us.html
Redirect 301 /side.php?id=456 /contact_us.html
I recommend this method because it redirects those who navigate to the outdated page to the new page that has similar content to the old one they were requesting instead of just redirecting them all to your home page.

Looking for guidance rewriting specific URL's

I have changed the CMS to my site and it has rewritten the URLs to be more friendly but I have 20 pages which are linked on different sites across the web. I want when people click those old links for them to be redirected to their new respective posts.
I was at first thinking of using a PHP array with a javascript redirect but now I'm thinking .htaccess mod-rewrite would be best.
Whats the best way to have specific URLs redirect to their new URLs?
Use the .htaccess file for redirects. For example:
# This allows you to redirect index.html to a specific url
Redirect /index.html http://example.com/location/
Add some regex to match your rewrites and send to the dynamically created remote url. For example:
# Dynamic redirect
RedirectMatch 301 yourUrl/\(.*)\$ http://external.com/someUrl.html?dynamicVal=$1
That would send ...yourUrl/123 -> http://external.com/someUrl.html?dynamicVal=123
If you are talking about URLs on your pages, then the best way is to edit all such pages with current proper URLs.
If you are talking about "what to do when someone hits my old URL (from their bookmarks or by clicking a link on another site, for example) then the best way is to redirect (with code 301) such requests to a new location using Apache's URL Rewrite module.
Example:
# Activate Rewrite Engine
RewriteEngine On
# redirect to another page on the same site
RewriteRule ^mypage.php /other/mypage.php [R=301,L,QSA]
# redirect to another page on ANOTHER site
RewriteRule ^mypage.php http://www.anothersite.com/mypage.php [R=301,L,QSA]
Here is the link to Apache's manual for mod-rewrite.
Another useful place -- Mod_Rewrite Forums.
Apache supports different modules to rewrite/redirect requested URIs:
mod_alias with Alias and AliasMatch for internal rewriting, as well as Redirect and RedirectMatch for external redirecting
mod_rewrite with RewriteRule for internal rewriting and external redirecting
The main difference between the mod_alias and mod_rewrite directives is that mod_alias’s Alias and Redirect directives work with path prefix patterns while the other directives (i.e. AliasMatch, RedirectMatch, and RewriteRule) work with regular expressions.
A path prefix pattern is always always matched when it’s a qualified prefix of the requested path and the remaining path segments are automatically appended to the target path. Here’s an example:
Redirect /foo/bar http://other.example/quux
If /foo/bar is requested, it’s getting redirected to http://other.example/quux; likewise /foo/bar/baz is getting redirected to http://other.example/quux/baz. Alias works alike but just internally.
In opposite to that, AliasMatch, RedirectMatch, and RewriteRule work with regular expressions and can be used not just to match path prefixes. Here’s an example:
RedirectMatch ^/foo/bar$ http://other.example/quux
If /foo/bar is requested, it’s getting redirected to http://other.example/quux (just like the Redirect example above). But if /foo/bar/quux is requested, it’s not getting redirected as ^/foo/bar$ doesn’t match /foo/bar/quux.
Futher differences between mod_alias and mod_rewrite are that mod_rewrite can also examine other parts of the URI except the path and even HTTP request header fields. It does also allow more complex operations with multiple conditions.

Alias within htaccess, and block access to original file? (URL rewriting)

I have a very basic two-page website: the home page, and an about page. What I'm trying to do is use htaccess to rewrite the URLs so that the appear as:
domain.com/ (for the home page)
domain.com/about (for the about page)
In the actual folder structure of the site, the homepage is /index.php and the about page is /about.php (both appear in root).
I've been doing research into using alias but unfortunately my hosting (Dreamhost) doesn't allow access to httpd.config so that's out the window and I'm left with using rewrite rules in the htaccess file.
Since the index.php file will appear in the domain root (http://domain.com/) automatically, I've so far managed to make the about page appear correctly at domain.com/about using these lines:
RewriteEngine On
RewriteRule ^about$ /about.php
I'm also using 301 redirects so that for example, domain.com/about/ (with the trailing slash) also directs back to the /about URL like this:
Redirect 301 /about/ http://domain.com/about
This works great.
However the index.php and about.php files still also show if you go to the correct URL within your browser (eg: domain.com/about.php) so as a result the search engines are seeing (and indexing) two versions of each page! I've set up the correct canonical metadata within each page but this doesn't seem to have had any effect (the canonical metadata have been within the page markup ever since the site went live).
So how would I go about firstly doing a 'blind' rewrite (for want of a more technical term) for the two files so that the URLs look correct, but also effectivly 'block' direct access to the files - ensuring that if someone were to attempt to access the php files directly, the URL would still appear in the visitor's browser as the 'pretty' versions rather than the full file name and php extension?
Any advise would be hugely appreciated, I've been researching this for another couple of days now (I don't think there's anything quite the same as this anywhere on here already) and cannot for the life of me work this one out!
Check $_SERVER['REQUEST_URI'] in the PHP files. If that contains the filename (instead of the URI that you want), then do a 301 or 404 or whatever you want. Else serve the page as usual.
You can also do a
RewriteRule ^about.php - [L,gone]
or
RewriteRule ^about.php /about [L,R=301]
but this has to go before your other RewriteRules. It will send a 410 Gone or a 301 Moved Permanently response if the page is accessed via /about.php. See Apache Module mod_rewrite for the complete documentation of mod_rewrite.

Categories