Rewrite a sub DIR - .htaccess

I have created a website using IPB which I believe is written in PHP, the URL is the forum at present is
what I would like is the URL to be rewritten to
and when user go to the index for force user to use instead of
any help with be greatly appreciated!

Make sure mod_rewrite is enabled and AllowOverride All is set in your conf file, and put these rules in the .htaccess file in the root of your web directory:
RewriteCond %{HTTP_HOST} !^www
RewriteRule ^(.*)$ http://www.thereviewforum.com/$1 [R]
RewriteCond %{HTTP_HOST} ^thereviewforum
RewriteRule ^forum(.*) http://community.thereviewforum.com$1 [R,L]
EDIT with full .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^thereviewforum.com
RewriteRule ^(.*)$ http://www.thereviewforum.com/$1 [R]
RewriteCond %{HTTP_HOST} ^www.thereviewforum
RewriteRule ^forum/?(.*) http://community.thereviewforum.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !.*\.(jpeg|jpg|gif|png|ico)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Related

.htaccess redirect from subfolder to domain not working properly

I am using PHP, Laravel 8 Framework, and cPanel for my website. What I am trying to do is something like this.
Redirecting Routes from
http://example.com/example.com/public/
http://example.com/example.com/public/about
http://example.com/example.com/public/contact
.
.
// more
to
https://example.com/
https://example.com/about
https://example.com/contact
.
.
// more
I have the .htaccess file in the domain root public_html folder.
.htaccess file
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^example.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /example.com/public/$1 [L]
Please guide me if I had done something wrong.
Please try following rules, with your shown attempts. Please make sure to clear your browser cache before testing your URLs. Make sure 2 things. 1st- Keep your htaccess rules file in same level where you have folder example.com and 2nd- keep your index.php inside /root/example.com/public folder.
Options -Indexes -MultiViews
RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/example\.com/public [NC]
RewriteRule ^(.*)/?$ example.com/public/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ example.com/public/index.php [L]

htaccess redirect http to https for subdirectory

I use this redirect because my website is inside a subfolder (www.domain.com/subfolder/)
So if someone enters the website, it will load like this: http://domain.com
What do I need to add or change in .htaccess so that it redirects automatically to https://domain.com, counting that the website is at domain.com/subfolder
I have tried various redirect codes, but no success. If someone is kind to point me in the right direction or give me a hint.
Thanks for the help.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ subfolder/index.html [L]
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^ https://{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteRule !^subfolder/ subfolder%{REQUEST_URI} [L,NC]

Hide Subfolder in URL with .htaccess without breaking other subdomains

I am trying to keep my main domain structure from being too cluttered so I am parsing all of my domains into their own subfolder. So, what I am trying to do is when a user goes to http://mydomain.com they are actually sent to http://mydomain.com/sub-directory
This bit of code works:
#redirect to submain subdomain
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /submain/
RewriteRule ^submain/(.*) /$1 [L,R=301]
RewriteRule !^submain/ submain%{REQUEST_URI} [L]
However it breaks all the other subdomains I have loaded into my main directory.
Any ideas on how to fix this?
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /submain/
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$
RewriteRule ^submain/(.*) /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$
RewriteRule !^submain/ submain%{REQUEST_URI} [L]
Create a .htaccess file in root folder, and put this content inside(just change example.com and my_subdir):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/my_subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir/index.php [L]
</IfModule>

.htaccess retrieve from folder if subdomain, not 301 redirecting?

I want my site to just point to /user folder if the request is a subdomain.
If the request is subdomain.site.com/admin, then the site should show the page for subdomain.site.com/user/admin.
The problem with my code is that it makes an 301 redirect instead of just keeping the url-address.
My code look like this:
<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.bildsida.se(.*)
RewriteCond %{HTTP_HOST} ^[^.]+.bildsida.se(.*)
RewriteRule ^$ user/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) user/$1 [L]
</IfModule>
And you can try for yourself, go to http://mickes.bildsida.se/admin and see how the address changes to /user/admin. Very disturbing...
You just need a few of the lines you showed to get this working.
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.bildsida.se
RewriteCond %{HTTP_HOST} ^.+\.bildsida\.se
RewriteRule ^(.*)$ user/$1 [L]
I adjusted the HTTP_HOST checks because that parameter only looks at the domain name, so you don't need the (.*) at the end. I also removed the checks that look if the file exists or is a directory, since you want everything redirected (no reason to make it possible to access files from other subdomains, for example)
You code can be simplified to these lines : (try them instead)
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)?bildsida\.se [NC]
RewriteRule ^(.*)$ /user/$1 [QSA,L]
Finally! After days and nights of reading forums and documentations, and testing all possible ways, I got it to work!
Sulotion:
<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.bildsida.se
RewriteCond %{HTTP_HOST} !^bildsida.se
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^$ user/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)? user/$1/ [QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /(.+)/ user/$1 [QSA]
</IfModule>

.htaccess doesn't work

I have the following .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^mykeyword$ news.php [L,QSA,NC]
However, when I open the news.php, the url is still the same, that is www.mydomain.com/news.php instead of www.mydomain.com/mykeyword
I make the following test:
RewriteEngine on
RewriteRule ^test\.html$ test.php [L]
I upload 2 files on my server, test.html and test.php and after I type www.mydomain.com/test.html, my php page was displayed, so that mean that I have no problem with my settings. What on earth I am doing wrong???
Any help will be deeply appreciated.
Regards,Zoran
Change your .htaccess to this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(mydomain\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+news\.php [NC]
RewriteRule ^ mykeyword [R=301,L]
RewriteRule ^mykeyword/?$ news.php [L,NC]
The rewrite rule translates from the URL supplied by the user to the URL seen by the server. Try browsing to www.mydomain.com/mykeyword - you should see the page news.php.

Resources