3

I am stuck in here with htaccess. I've searched and tried many tutorials and problem solutions but couldn't achieve what I want.

I want to remove folder names from the website link. My htaccess file is in the root directory i.e "testing"

What my link looks like:

http://localhost/testing/sub/test.php

What I want:

http://localhost/test.php

Following is my htaccess

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /(.*) /testing/sub/$1    [L]
5
  • "My htaccess file is in the root directory i.e 'testing'" - This is a bit misleading, since testing would seem to be a subdirectory off the root directory. Is /testing/sub/test.php your actual file location? In which case, your links should actually look like /test.php, not /testing/sub/test.php as you state. Only then do you internally rewrite the request back to /testing/sub/test.php (which is what your code is trying to do). Commented Jan 8, 2016 at 14:55
  • Yes. "xampp/testing/sub/test.php" is my file location. I want my url to look like "localhost/test" Commented Jan 8, 2016 at 15:01
  • 2
    Then the first thing to do is change the URL in your application. This isn't something you do in .htaccess (unless you need to correct indexed or linked to URLs). When the URL "looks" the way you want, then use .htaccess to internally rewrite the request to the real URL. Commented Jan 8, 2016 at 15:02
  • First you say you want the URL to be localhost/test.php, and then you say you want it to be localhost/test. Which one is it? Commented Jan 9, 2016 at 6:57
  • localhost/test.php Can I use str_replace to replace the url segment ? Commented Jan 11, 2016 at 8:32

2 Answers 2

4

Use this line in your root .htaccess

RewriteRule ^test.php$ /testing/sub/test.php

Sign up to request clarification or add additional context in comments.

Comments

0

The best way to do that is to go to the folder that contains all the files for your site . For example if the folder is named " site1 " go to it form your cpanel copy all the files to your Public_html folder

one way to do that is once you locate the folder that has your site files and you are looking at them , click on select all to select all the files or if you do not see select all click on the first file in the folder it should be highlighted then scroll down to the very last file of the folder press the shift button on your keyboard and click the last file now everything should be highlighted. if not repeat the process again until everything is highlighted .

right click and click on copy

on the little popup window on the bottom you should see copy file to make sure the folder you're copying the files to is /public_html then click on the copy files button on the lower right corner of the popup window .

all of your files should now be in the pulic_html folder you need to now change your configuration.php file right click on and click on edit once the popup window opens click on edit again it should open in your browser look for the code line that says :

public $live_site = 'http://vivendishop.com';

if your domain name has a /folder remove it and save

that should do it hope that works for you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.