I have the current domains
http://domain.com/dev/programme and http://domain.com/dev/software
But I want to point them to http://domain.com/dev/programmes http://domain.com/dev/softwares
I have set up the following htaccess
Redirect 301 /new/programme http://www.domain.com/new/programmes/
Redirect 301 /new/software http://www.domain.com/new/softwares/
This works but the problem comes when you try access sub pages of the main links. The sub pages rely on the slug in the url.
eg. http://domain.com/dev/programme/page and whenever I try access this page with htaccess set like the above it sends me on a redirect loop.
How would I be able to keep the link like http://domain.com/dev/programme/page but have it http://domain.com/dev/programmes whenever its accessed?
Try this:
RewriteEngine On
RewriteRule ^dev/programme$ dev/programmes [L]
RewriteRule ^dev/software$ dev/softwares [L]
RewriteRule ^dev/programme/(.*)$ dev/programmes/$1 [L]
RewriteRule ^dev/software/(.*)$ dev/softwares/$1 [L]
You can do this in a single rewrite rule:
RewriteEngine On
RewriteRule ^(dev/programme|software)(/.*)?$ /$1s$2 [L,NC]
Related
With RewriteRule I've always cleaned my URLs as following:
RewriteRule ^page/(.*)$ page.php?urlkey=$1 [QSA]
My new host doesn't allow me to use Options +FollowSymLinks and therefore I cannot use the / anymore. So I've changed my RewriteRule to:
RewriteRule ^page-(.*)$ page.php?urlkey=$1 [QSA]
However, I need to redirect all my former URLs to the new version. I tried doing this using the following rule:
RewriteRule ^page/(.*)$ page-(.*)$ [R=301,L]
This is however not working. I've also tried to just make a Redirect in my .htaccess:
Redirect 301 https://www.example.com/page/urlkey https://www.example.com/page-urlkey
This is also not working.
EDIT
As requested the actual code below:
RewriteEngine on
RewriteRule ^citywalk-(.*)$ citywalk.php?urlkey=$1 [QSA]
RewriteRule ^citywalk/(.*)$ citywalk-(.*)$ [R=301,L]
For example the citywalk The Historical Centre has a urlkey the-historical-centre. The old url is citywalk/the-historical-centre.
To test this specific case and other technique:
Redirect 301 /citywalk/the-historical-centre https://example.com/citywalk-the-historical-centre
By visiting https://example.com/citywalk/the-historical-centre no redirecting takes place (the url stays the same in the browser) and no urlkey is found.
In .htaccess I want to redirect urls like this:
/products.php/a7-frames
/products.php/a6-frames
to this:
/picture-frames/a7-frames
/picture-frames/a6-frames
So need to substitute products.php with picture-frames.
After a lot of Googling I tried this:
RewriteBase /
RedirectMatch 301 (.*)\.php/?$ https://www.domainname.com/picture-frames$1
But it doesnt work, if I enter this url: /products.php/a7-frames the browser says there are too many redirects and goes to:
/picture-frames/index
It's substituting the products.php for picture-frames which is great, but I'm not sure why it adds "index" on the end rather than the /a7-frames part of the url? How can I fix this?
You can use these rules in your site root .htaccess:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+products\.php/([^\s?]+) [NC]
RewriteRule ^ /picture-frames/%1? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^picture-frames/([^/]+)/?$ products.php/$1 [L,NC]
Make sure to clear your browser cache before testing this change.
Have a website with subpages all in this format:
mydomain.com/something
That's fine. But what is NOT fine is that you can also do mydomain.com/something/index.php (you can enter address in this format into your browser) and you still get the content on that mydomain.com/something.
I don't want those two possibilites to be available at the same time, Google doesn't like this. I want just one to be possible.
So what I want to do is whenever you type into your browser mydomain.com/something/index.php, you will be redirected to mydomain.com/something (without that /index.php at the end).
How should I write a .htaccess code to do something like this?
add the following lines to .htaccess in the root directory of your website
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(.*?)/?index.php$ /$1 [R=301,L,NC,QSA]
Note: the first condition assure that no previous redirection is made (to prevent redirection loop)
Mordor:
You can try this in your .htaccess file:
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
I have looked but can't find anything that works. I have an old site that we have updated. They had everything under a folder called site under the root. Now all the customers who have this bookmarked I would like to redirect them, regardless of what is after the folder site (subfolders, files), to the main page of the new site instead of page not found on our new WordPress install. Any help appreciated.
Old URL: http://www.oldsite.com/site/.... to new URL http://www.newsite.com
I have tried this to no avail
Rewrite Rule ^site/(.*)$ http://www.newsite.com
Thanks.
try:
RewriteEngine On
RewriteCond %{HTTP_HOST} oldsite.com$ [NC]
RewriteRule ^site/(.*)$ http://www.newsite.com/$1 [R=301,L]
This redirects something like http://www.oldsite.com/site/some-page.html to http://www.newsite.com/some-page.html (the matching bit of the URI after /site/ gets carried over in the 301 redirect), but if you want to redirect everything for /site/ to the index root of newsite, replace the target in the RewriteRule to http://www.newsite.com/ (remove the $1 bit).
EDIT:
I actually write it wrong above. It is actually the same domain name. The question should read old URL mysite.com/site.... everything under this folder to just redirect to mysite.com
Then what you want is:
RewriteEngine On
RewriteRule ^site/(.*)$ /$1 [R=301,L]
Or alternatively with mod_alias:
RedirectMatch 301 ^/site/(.*)$ /$1
Looks like all you need is this simple 1 liner rule:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^site/ / [R=301,L,NC]
How do I get the following redirect to work?
olddomain.com/employee-scheduling-software.html
To redirect to
newdomain.us/employee-scheduling-software.html
I do have mod_rewrite on, but I'm basically a complete novice in this area
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^employee-scheduling-software.html$ http://newdomain.example.org/employee-scheduling-software.html
</IfModule>
You can change the rule into:
RewriteRule ^employee-scheduling-software.html$ http://newdomain.example.org/employee-scheduling-software.html [R=301]
which will send a 301 Moved Permanently header to the browser, so it updates its bookmarks and stuff.
You could use this code in .htaccess on olddomain.com:
RewriteEngine on
RewriteRule ^employee-scheduling-software\.html$ http://newdomain.us/employee-scheduling-software.html [R,QSA]
Since the ^employee-scheduling-software\.html$ is a PERL regex, you need to escape the dot in ".html" with a backslash (\.).
This will just redirect employee-scheduling-software.html to the new domain. If you want to redirect all files to the new domain, use:
RewriteEngine on
RewriteRule ^(.*)$ http://newdomain.us/$1 [R,QSA]