Redirect all posts to subfolder - .htaccess

I have a website like this :
domain.com/offer1.html
domain.com/offer2.html
etc.
I need to move those pots (offer1.html, offer2.html, etc )to a subfolder :
domain.com/folder/offer1.html
domain.com/folder/offer2.html
How can I redirect all those pots ? I can do it one by one by, but there are more than 1000. So looking for an easy way
Thank you in advance

If I understand your question correctly, to redirect all the offer pages in the root folder to this folder try the following:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/offer*.html
RewriteRule ^/(.*)$ http://%{SERVER_NAME}/folder/$1 [L,R]
Does this help?

Related

Redirection using htaccess file from one domain to another

I have a website with the name of "http://wowriters.com/" but that website is also accessable from "http://beeelkazi33813.ipage.com/writers/".
I want that my "http://wowriters.com/" website should not be accessible from "http://beeelkazi33813.ipage.com/writers/".
Please help me.
Thanks in advance.
Inside your site root directory (/writers/), add this block rule for 2nd domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} =beeelkazi33813.ipage.com
RewriteRule .* http://wowriters.com/$0 [L,R=301,NE]

Redirect PHP URL with parameters

I have a website with several URLs like these:
domain.com/aff_link.php?id=363
and I need to redirect all of them to a subfolder called "old"
like this:
domain.com/old/aff_link.php?id=363
those numbers at the end go from 2 up to 4 digits.
How can I do this in htaccess?
Currently I have this code
RewriteCond %{QUERY_STRING} (^|&)(id)=[^&]+ [NC]
RewriteRule ^(/.*)?$ http://domain.com/old? [R=301,L,NC]
but that redirects everthing to domain.com/old/
so as you can see I do not know what I am doing, please help.
Thank you in advance.
This should be pretty close ...
RewriteEngine On
RewriteRule (aff_link.php) old/$1 [L,QSA,R=301]
Watch out for leading slashes depending on whether this is in a VirtualHost or Directory or .htaccess block.

Hiding Directory in URL with htaccess is not working

I have website1.com setup so that when users visit website1.com they get redirected via a meta tag in an index.html to website1.com/directory
Then they use the website and go to links such as website1.com/directory/index.html or what ever. I am trying to hide the "directory" in the link so that users only see website1.com/index.html
I have place the htaccess which is to rewrite the url to website1.com/index.html at website1.com/directory/.htaccess
I am not doing anything else special and this should be an easy task. My current exact htaccess is as follows:
RewriteEngine On
RewriteCondition %{REQUEST_URI} !^directory/
RewriteRule ^(.*)$ directory/$1 [L]
Should be easy right..... All I get is a 404
In my server I have Mod_Rewrite & mod security and suspect one of them is causing this not to work but can't imagine why. Am I missing something here?
Your rule is incorrect since %{REQUEST_URI} variable has starting /
You need to place this in document root
Use this code in document root .htaccess:
RewriteEngine On
RewriteCondition %{REQUEST_URI} !^/directory/
RewriteRule ^(.*)$ /directory/$1 [L]

.htaccess redirects : posting the subsequent uri

I have a website set up where I store all my user profiles in /member-centre/member-directory/USERNAME
My problem is that a number of referrals are posting to a depreciated structure of /members/USERNAME
Is there a way I can configure my .htaccess file to automatically post the requested USERNAME to the correct location? All i've found on google is static redirection.
If this is not possible through .htaccess, is there another method I could use?
Many thanks in advance
If you are looking for a redirect solution, Jon Lin's will work fine. If you want to do a rewrite then put the following in your .htaccess file in the root of your domain
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/members/([^/]+)$ [NC]
RewriteRule . member-centre/member-directory/%1 [L]
if member/centre etc is relative to the root filesystem and not your domain then replace the last line with (just leading slash)
RewriteRule . /member-centre/member-directory/%1 [L]
Do you mean something like:
RedirectMatch 301 ^/members/([^/]+)/? /member-centre/member-directory/$1
This redirects the browser with a permanent redirect.
Try something like this:
RewriteRule ^members/ /member-centre/member-directory/ [L]

How do I use .htaccess to change the structure of my website?

I'm doing some reorganizing on my web server and would like to change the way my structure works. Currently, everything is stored at the lowest level so that when I access my site the url looks like this:
www.example.com
www.example.com/page1.php
I have many pages in my site and i would like to move them out of the main folder. eg.
www.example.com/folder/
www.example.com/folder/page1.php
however, I would like for users not to see the /folder/ section of the url. In other words, when a user visits my site, I want him to navigate to:
www.example.com/page1.php
www.example.com/myfolder1/page1.php
www.example.com/myfolder2/page2.php
www.example.com/anyfoldername/anypagename.php
but actually be at
www.example.com/folder/page1.php
www.example.com/folder/myfolder1/page1.php
www.example.com/folder/myfolder2/page2.php
www.example.com/folder/anyfoldername/anypagename.php
I want the url to show without the /folder at all times.
Is there a way to do this with the .htaccess file?
You can easily do this using mod_rewrite. For example:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^page1\.php$ /folder/page1.php [L]
NOTE:
This is to be placed in .htaccess in your website root folder. If placed elsewhere some small tweaking may be required.
UPDATE:
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule ^(.*)$ /folder/$1 [L]
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]*)$ folder/$1 [L]

Resources