I need to re-direct all traffic coming to domain.com/index.php to domain.com/forum/index.php
Example:
Original request: domain.com/index.php?topic=11841.0
Re-direct to: domain.com/forum/index.php?topic=11841.0
Also
Original request: domain.com/index.php/board,200.0.html
Re-direct to: domain.com/forum/index.php/board,200.0.html
But only traffic that is coming to index.php with a query string must be redirected. All other traffic to domain.com must not be redirected, and traffic to index.php without a query string should also not be re-directed.
We just moved a forum that resided on the root of the domain to a subfolder. The root of the domain now has a Wordpress installation, but we want all old forum discussion links to be re-directed to its new subfolder.
TIA
To redirect /index.php/* to /fourm/index.php/* you can use the following Rule in your /root/.htaccess :
RewriteEngine on
RewriteRule ^index.php/(.*)$ /fourm/index.php/$1 [L,R]
This will redirect all requests including query string and path info from /index.php to /fourm/index.php . If you want to redirect the url only when there is a query string , use the following Rule :
RewriteEngine on
# if query string is present
RewriteCond %{QUERY_STRING} .+
# redirect "/index.php" to "/forum/index.php
RewriteRule ^index.php$ /forum/index.php [L,R]
The Rule above will redirect /index.php?queryString to /fourm/index.php?queryString .
Related
Is it possible to use .htaccess to transparently rewrite a subdomain to show the content of the root domain while making the subdomain name available in the query string?
For example:
https://sub.example.com/
transparently shows the content of:
https://www.example.com/?sd=sub
Another example:
https://sub.example.com/page.php?a=1&b=2
transparently shows the content of:
https://www.example.com/page.php?a=1&b=2&sd=sub
I've tried multiple solutions and so far this is the closest I've gotten:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule ^(.*)$ https://www\.example\.com?sd=%1 [QSA,L]
The only issue is that it redirects instead of rewriting. As you can see, I am not using the [R] flag so I don't understand why it redirects unfortunately. Also, I need to have the subdomain created in the hosting account for it to work...for example: https://test.example.com redirects to https://www.example.com?sd=test with the .htaccess above and that rewritten URL is shown to the visitor. I also have to have the subdomain test.example.com created in the server for this to function.
This is the current rule in the htaccess
# Redirect
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ http://new.com/$1 [R=301,L]
</IfModule>
Works fine so far but it should have one exception: if it is the home page it should redirect to a specific url. So if its http://old.com/ it should redirect to http://new.com/shop in every other case it should behave like above so http://old.com/cat/xyz redirecting to http://new.com/cat/xyz and so on.
Any suggestions?
.* in regex matches everything including landing page URI i.e. / but .+ skips landing page.
You can use these rules:
RewriteEngine On
# handle landing page
RewriteCond %{HTTP_HOST} ^(?:www\.)?old\.com$ [NC]
RewriteRule ^$ http://new.com/shop [R=301,L]
# everything but landing page
RewriteCond %{HTTP_HOST} ^(?:www\.)?old\.com$ [NC]
RewriteRule . http://new.com%{REQUEST_URI} [R=301,L,NE]
301 a single page URL to another
To create a 301 redirect from one URL to another URL, add the
following line of code:
Redirect 301 /retiredpage.html http://www.example.com/newpage.html
You can add as many of these redirect lines as necessary to the .htaccess file.
301 a directory URL and all of its contents to another
If you have redesigned your site architecture and renamed a directory, you need to create a 301 for the entire directory. Here’s how:
RedirectMatch 301 ^/oldname/ http://www.example.com/newname/
301 a domain name URL to another
If you just bought an aged domain name whose traffic (and search page rank value) you want to use to augment that of your existing site’s domain, you can set up a 301 to transfer all traffic and ranking from the purchased domain name to your current site.
Use the following code as an example:
RedirectMatch 301 ^(.*)$ http://www.example.com
Be sure you set up this redirect code in the .htaccess file of the source site you want redirected, not the redirect target site!
301 domain name URL variants for canonicalization
Since search engines index URLs, having multiple URLs in the index that point to the same content page divides the available page rank credit for that page among those URLs. This is definitely a “not optimized for search” state of affairs! To learn more about the details of canonicalization, take a look at the Search Engine Land post Why Canonicalization Matters From A Linking Perspective. The bottom line is you want to consolidate the page rank to one (canonical) URL to optimize the search value of that content.
Once you understand canonicalization best practices, you’ll want to implement them on your site. That means you must account for all redirecting possible alternative URL variations to the canonical URL. Use the following code sample for your site’s home page:
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(default|index)\.(html|php|htm)\ HTTP/ [NC]
RewriteRule ^(([^/]+/)*)(default|main|index)\.(html|php|htm)$ http://www.example.com/$1 [L,R=301]
The first two-line block of code redirects URLs that have omitted the “www.” prefix to the full “www.example.com” home page URL. That means the home page URL
**
http://example.com will not resolve on its own, but instead will redirect to http://www.example.com/.
**
The second code block redirects URLs specifying default page references to the URL that omits default page reference names. This code ensures that any home page URL that includes several versions of explicit page name references, such as default.htm or index.html, will be redirected to the canonical home page URL,
http://www.example.com/.
I always set my domains to avoid www and use http://, however google never indexes http://, which means in the google results my website always shows up as mywebsite.com only.
# activate URL rewriting
RewriteEngine on
# Remove www
RewriteCond %{HTTP_HOST} ^www.mywebsite.com$ [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [R=301,L]
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(index\.php|public|images|robots\.txt)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt|sitemap\.xml)
# but rewrite everything else
RewriteRule ^(.*)$ index.php?/$1 [L]
Has the issue anything to do with my .htaccess file?
You can't force google to show http:// , google always remove it if url starts with http:// he will keep it if url starts with https://
You can control www with your htaccess file, but not http:// , and purpose of that http://mywebsite.com/$1 is not to tell him to show http:// , you must specify protocol otherwise he will act like you specified local address.
If you check urls in google results you can confirm this, google will show protocol part just if it's not http
I know how to redirect normal links without strings, but including the string for email addresses has me stuck. Can someone please assist with 301 redirecting a URL to another domain including the URL string? I need to redirect the following:
www.domain.com/page.php?e=tom-jones#mail.com
to
www.domain1.com/?e=tom-jones#mail.com
I just need to keep the email address in the string when it's redirected to the new URL
Thanks in advance.
In the htaccess file in your www.domain.com document root, you can just add:
RedirectMatch 301 ^/page\.php$ http://www.domaon1.com/
The query string will automatically get appended. Or you can use mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^page\.php$ http://www.domaon1.com/ [L,R=301]
I have a website on a test server and I want to rewrite URL for this website because it is very long
I wish our visitors instead of entering this URL:
http://staging.company.fr/site2.it/s...oject2/public/
enter this URL:
www.monsite.com
I created a file. htaccess:
RewriteEngine On
RewriteRule ^/~(.+) http://www.monsite.com/~$1 [NC,L]
but does not work
While in .htaccess mod_rewrite doesn't match leading slash in a URL since it is applied per directory. Therefore following should work:
RewriteEngine On
RewriteRule ^(.+)$ http://www.monsite.com/$1 [L,R=301,NE]
This will redirect every URL in your existing domain other than home / to monsite.com
Reference: Apache mod_rewrite Introduction