I am sure this already exists, but I'm not too sure the terminology to search for exactly what I am looking for.
I have a url like http://www.example.com/members/$variable/achievements and I want all of these page to redirect to one level up, for example http://www.example.com/members/$variable.
I was originally using :
RewriteEngine On
RewriteRule ^members/([\w]*)/achievements/$ http://www.example.com [R=301,L]
which works fine for redirecting the original page to the homepage, but I would rather it go to that variable page.
RewriteEngine On
RewriteRule ^members/([^/]+)/achievements/?$ http://www.example.com/members/$1/ [R=301,L]
This assumes there is something after $variable/achievements (with and without the ending /) and redirect it back to http://www.example.com/members/$variable/
Related
I'm new at programming. We have an office project, the website's URL is www.project.com.ph (sample name), this is already a live website from the client. But the released printouts have the instructions for the users to go to www.project.com/ph which is wrong and we can't reprint the material since it already reached plenty of event places.
Now the problem is, we need to redirect to www.project.com.ph automatically if the users type in the browser's address bar www.project.com/ph. I ask if this is possible without any kind of CMS or Wordpress and how to actually do it? We bought a new domain www.project.com for this. Any kind of help is appreciated.
Try the following near the top of your .htaccess file in the root of www.project.com. This works OK (although marginally less efficient) if both domains are pointing to the same place, since it specifically checks that we are requesting the "wrong" domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?project\.com$ [NC]
RewriteRule ^ph/?(.*) http://www.project.com.ph/$1 [NC,R=302,L]
This will redirect requests for www.project.com/ph (no slash), www.project.com/ph/ (with a trailing slash) and www.project.com/ph/<whatever> to http://www.project.com.ph/<whatever>.
This is a temporary (302) redirect. Change it to a permanent (301) only when you are sure it's working OK.
From kj.'s answer on a similar question, here
In your .htaccess for www.project.com, this should do the trick.
RewriteEngine on
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
This will redirect any request to project.com to the domain http://www.project.com.ph/
To include the path after the /ph/` you can use this.
RewriteEngine on
# redirect including path after ph/ (e.g. project.com/ph/directory/file.php to project.com.ph/directory/file.php
RewriteRule ^ph/(.*)$ http://www.project.com.ph/$1 [R=permanent,NC,L]
# redirect any other requests to project.com.ph index
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
You can redirect (301 redirect) the URL using RewritrRule in .htaccess file
RewriteRule "http://www.project.com/ph/(.*)" "http://www.project.com.ph/$1" [L,NC,R=301]
Trying to make the url:
www.google.com/forum.php?fid=5
Redirect to:
www.google.com/new.php?fid=5
But also need it to keep everything else intact because for example the link can be:
www.google.com/forum.php?fid=5&sortby=asc
And need sortby portion to be there upon redirect.
What the redirect needs to do is look for forumdisplay.php and fid=6 and when both are found in the same url it redirects to blog.php and removes fid=6 but keeps any other parameters there.
I searched and found how to do it with one string but not two.
Also, what's the difference between redirect and rewrite?
This is related to MyBB forum software. I made a separate php file that uses forumdisplay but with a new name.
Using mod_rewrite you could use a condition to verify the id and grab what comes after if anything:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/forumdisplay.php
RewriteCond %{QUERY_STRING} ^fid=6(&.*|.*)
RewriteRule ^.*$ /blog.php?%1 [R=301,L]
I've been searching and searching for an answer and decided it may be best to ask. I am trying to redirect the following:
redirect 301 /store/?p=3m_controltac http://www.designtoprint.com/3m-controltac
I know it has something to do with using a GET variable but every example I've tried ends without success.
You cannot do this with Redirect directive as it does not work with GET variables. Your best choice is to use mod_rewrite (or implement it in your webpage (e.g. php file) directly):
RewriteEngine On
RewriteCond %{QUERY_STRING} =p=3m_controltac
RewriteRule ^store/$ http://www.designtoprint.com/3m-controltac? [R=301,L]
This will redirect (using 301 code) from /store/?p=3m_controltac to http://www.designtoprint.com/3m-controltac ONLY (no other URLs will be affected).
I will soon relaunch my whole website on the same domain, and so i would like to redirect all old url's to the new homepage. I've been looking around and have found lots of ways to do that, but no one works for me. I guess i need help from someone who really understands.
The current url's are like this:
http://www.ffsolar.com/produtos/index.php?lingua=por
http://www.ffsolar.com/contacto/index.php?lingua=eng
http://www.ffsolar.com/inicio/index.php?lingua=ger
Which i want to redirect to the new
http://www.ffsolar.com
The old folders and files will no longer exist after the relaunch, so i think that the redirect 301 method won't work.
So, my question is how do i do that? Do i have to use a mod-rewrite, or a simple redirect for all the old url's?
You could use ErrorDocument 404 /
Or you create a RewriteRule for each url that no longer exists:
E.g.:
RewriteEngine on
RewriteRule ^/produtos(.*)$ / [R]
RewriteRule ^/contacto(.*)$ / [R]
RewriteRule ^/inicio(.*)$ / [R]
You could also use RewriteRule ^produtos(.*)$ http://www.ffsolar.com/ [R]
So every url with e.g. /produtos or /contacto or /inicio will be redirected to the document root of this domain.
Also http://www.ffsolar.com/produtos/index.php?lingua=por or even http://www.ffsolar.com/produtos/just/example/random.php
How to redirect my url - www.example.com/home.php?rid=888601032
to www.example.com/examplepage.php
i have tried several htaccess codes 7 Im new to htccess, I would appreciate if someone can give me the correct redirect code.
The redirect you need is incredibly simple.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(home\.php)?\?rid=888601032\ HTTP/
RewriteRule ^(home\.php)?$ http://www.example.com/examplepage.php? [R=301,L]
It redirects any root request with the RID within it.
The syntax is:
redirect accessed-file URL-to-go-to
There are 3 parts;
(1) the Redirect command,
(2) the location of the file/directory you want redirected, and
(3) the full URL of the location you want that request sent to.
These parts are separated by a single space and should be on one line.
For example, if you want to redirect users from oldfile.html in the www directory of your account, myaccount, to newpage.html, the syntax should be
redirect /~myaccount/oldfile.html http://www.indiana.edu/~myaccount/newpage.html
Put this in yout .htaccess file:
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} rid=888601032
RewriteRule ^home.php examplepage.php [R,L,QSA]
If you dont want the redirect to be visible, leave the [R] flag.
Hope this helps!
Wouldn't be better to use php to do this?
if ((int)$_GET['rid'] == 888601032) // or something like this
header('Location: examplepage.php');
It depends on what you want to do, but it would be more flexible if you want to redirect to a different page depending on the "rid" parameter, or if you want to do some operation (like setting a cookie) before redirecting the user.