6

My aim is:

domain.com/folder

rewrite ->

domain.com

this shall concern ALL links inside that site. I mean on the site are links like:

domain.com/folder/forum.html
domain.com/folder/community.html

etc.

This is my aim:

domain.com/forum.html
domain.com/community.html

etc.

and its very important that the "folder" is never in the url in the adressbar visible.

I tried already many codes but I couldnt really solve this problem. My best try was with this code:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)folder
RewriteRule ^(.*)$ folder/$1 [L]

If I enter

 domain.com 

I get the content of

 domain.com/folder

displayed, what is correct ("folder" is not in the url shown). But when i click on some links of the site like: domain.com/folder/community.html then I can see again "folder" in the url, but I want that it becomes ALWAYS removed.

here is my site:

thewedgiecommunity.x10.mx/wedgiecommunity/

My aim is to remove the "wedgiecommunity" (=folder) This link is working

  thewedgiecommunity.x10.mx/

But when you click on Community (

 thewedgiecommunity.x10.mx/wedgiecommunity/community.html

) then i get again "wedgiecommunity" in the URL.

Would be awesome when someone could help me

anubhava
  • 761,203
  • 64
  • 569
  • 643
Bardock
  • 237
  • 2
  • 4
  • 9

2 Answers2

7

You can use this code:

Goes in DOCUMENT_ROOT/wedgiecommunity/.htaccess:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+wedgiecommunity([^\s]*) [NC]
RewriteRule ^ %1 [R=301,L]

Goes in DOCUMENT_ROOT/.htaccess:

RewriteEngine On

RewriteRule !^/?wedgiecommunity wedgiecommunity%{REQUEST_URI} [L,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • doesnt work. Its still the same with this code. When I go to thewedgiecommunity.x10.mx/wedgiecommunity/community.html I still see the "wedgiecommunity" (=folder) in the URL.l – Bardock Oct 15 '13 at 19:52
  • +1 but I think you're catching an extra `/` in your condition (in the `%1` capture group). – Ravi K Thapliyal Oct 15 '13 at 19:53
  • @Bardock: Q1. Is this the only .htaccess or do you have another in wedgiecommunity? Q2. Is this the only code in this .htaccess? If you have some other code then please post it in question? Q3. What is location of above .htaccess? – anubhava Oct 15 '13 at 20:51
  • A1: yes I have another .htaccess, in wedgiecommunity. But I cant post all its content here, because of char limit. A2: yes, I completely replaced the old code with this code. A3: its in the public_html folder I can give you FTP Access if you think it helps. – Bardock Oct 15 '13 at 21:46
  • hmm okey, it removes now the wedgiecommunity everywhere. but now i get 404 Error Codes on the website... I m really confused now. Maybe its practical impossible what I want? – Bardock Oct 15 '13 at 22:05
  • i dont know if its relevant, but this site is based on the CMS Joomla and its SEF Function is activated. The SEF Rules are in the wedgiecommunity/.htaccess – Bardock Oct 15 '13 at 22:25
  • You should be all set now. Make sure to clear Joomla cache and browser cache before you start testing. Site is accessible using `http://thewedgiecommunity.x10.mx` and other pages as `http://thewedgiecommunity.x10.mx/about/rules.html` – anubhava Oct 15 '13 at 23:02
  • AWESOME MATE! You did it! There is now only one thing missing. Before I gave you the FTP account I removed this code from wedgiecommunity/.htaccess RewriteCond %{QUERY_STRING} ^view=(registration)$ [NC] RewriteRule ^component/users/$ %1.html? [R=301,L] RewriteRule ^community/register.html registration.html [R=301,L] (RewriteBase was also /wedgiecommunity) now I have added this rules again, but they dont work anymore. Background: http://stackoverflow.com/questions/18884082/htaccess-rewrite-url-with-a-question-mark-only-for-1-specific-url – Bardock Oct 15 '13 at 23:36
  • Now when I click http://thewedgiecommunity.x10.mx/component/users/?view=registration I get http://thewedgiecommunity.x10.mx/wedgiecommunity/registration.html But my aim is: http://thewedgiecommunity.x10.mx/registration.html the same belongs to the other rule. I have modified the .htaccess. Maybe you can check it via FTP? – Bardock Oct 15 '13 at 23:38
  • Sorry I just came online. Let me check the rules and revert back. – anubhava Oct 16 '13 at 08:14
  • I have fixed your `.htaccess` for both of these 2 rules. Check them out. – anubhava Oct 16 '13 at 11:33
  • You nearly fixed it :) . The last rule is still wrong. it redirected me to thewedgiecommunity.x10.mx/register.html aim is: thewedgiecommunity.x10.mx/registration.html I have changed the FTP Account Credentials, but at the moment the webhost got some internal server problems. If they are again online I will send you the FTP Account. And THANK YOU VERY VERY MUCH FOR HELPING SO MUCH!!!!!!!! – Bardock Oct 16 '13 at 21:30
  • hey, support of my webhost said that the .htaccess causes the 500 internal server error. could you please fix it :) ? I have made a new FTP Account... but how can I send you the credentials in private? – Bardock Oct 18 '13 at 13:50
  • send me an email `anubhava[AT]aol[DOT]com` and I will take a look – anubhava Oct 18 '13 at 13:54
  • he mate, I think I have found a workaround. These htaccess rules were just one of a possible solution of my originally problem. I didnt thought that it would be complicated like that :) . But i am nearly to fix it on an other way. Nevertheless BIG THANK YOU!!! So shall I mark your post as the right answer? A shame that i cant give you reputation :S – Bardock Oct 18 '13 at 15:56
1

You can use this rule to "remove" the folder from the URL when it is accessed directly via the browser:

RewriteCond %{THE_REQUEST} \ /wedgiecommunity/
RewriteRule ^wedgiecommunity/(.*)$ /$1 [L,R=301]

Then your other rule will handle the rest.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • doesnt work. Its still the same with this code. When I go to thewedgiecommunity.x10.mx/wedgiecommunity/community.html I still see the "wedgiecommunity" (=folder) in the URL. – Bardock Oct 15 '13 at 19:55