Remove directory from url htaccess apache - php

I have website where all the files were in the public_html root so my urls were http://foo.com/index.php
I have moved all my files into a bar directory so now the url is: http://foo.com/bar/index.php however I would like to rewrite the URLs so that the the directory bar is not shown in the urls and the site still appears as http://foo.com/index.php. What is the best way of achieving this? I have LAMP hosting and can change htaccess files.
Thanks in advance.

Put this code in your .htaccess under public_html:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^((?!bar/).*)$ bar/$1 [NC,L]
Then you can access your website as http://foo.com/index.php

Related

Error on using .htaccess

I'm trying to use my .htaccess file but I still can't figure it out what am I doing wrong.
I only want my domain to be yescpol.com.br, and it always comes like this
My .htaccess is inside the folder "porcelanato" and it has this code:
RewriteEngine on
RewriteBase /porcelanato/
I only want my index.php to turn into yescpol.com.br
What am I doing wrong?
The easiest thing to do would be to change the DocumentRoot in the domain configuration or move your files out of that folder and into the root.
If you want to stick with the rewrite method, you will need to add a rule like this.
RewriteEngine On
RewriteRule ^$ /porcelanato [L]
Add this line to the top of your .htaccess file:
DirectoryIndex index.php
Though if this property is set properly on your apache service in httpd.conf (or whatever is serving your pages) this won't have to be added to your .htaccess file.

php: move the sitemap.xml into folder

There is a website having the multi-language functionality archieved by the .htaccess file.
I have generated the sitemap.xml file and I can access it with sitename.com/sitemap.xml
Having a little experience in php, I would ask how can I 'move' the .xml file into a place so that I can access it via sitename.com/ro/sitemap.xml ?
You can just keep sitemap.xml in root folder and add this rule in DocumentRoot .htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^ro/(sitemap\.xml)$ /$1 [L,NC]
Now you can use this URL as http://sitename.com/ro/sitemap.xml

URL Rewriting .htaccess

I'm having some problems with the .htaccess file. I'm working on a REST API and I'm rewriting my URL's, if I put .htaccess at the root of my server (localhost) everything works fine, but I actually don't want to put my .htaccess file there but in my project directory.
For example I want to type
http://localhost/myproject/player/id/etc..
and not just
http://localhost/player/id/etc...
The problem is that if I use
http://localhost/myproject/player/id/etc..
The redirection works correctly but in my controller.php file the Path variable I retrieve is /myproject/player/id. Is there a way to remove /myproject/ from the URI in the .htaccess file, or more generally is it possible to remove the directory of the folder containing the .htaccess from the REQUEST_URI variable ?
ok. try this- in your .htaccess write-
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^myproject/(.*)$ /$1 [L,NC,R]
it will remove myproject from your url.

Subfolders Url rewriting using htaccess

i am working within sub folder of my website and i want to rewrite my urls.
i have never done this before nor have any knowledge of rewriting rules.
I have a file which named show.php which takes parameter id which is any no and then it echo that no on to the screen.
Now this file is in folder name polo.
www.xyz.com/polo/show.php
i want to rewrite
www.xyz.com/polo/show.php?id=10
to
www.xyz.com/polo/id/10
I tried this answer but still its not working.
Subfolders using htaccess
Any help would be appreciated.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(polo)/(id)/([0-9]+)/?$ /$1/show.php?$2=$3 [L,QSA,NC]

unable to change url with .htaccess in godaddy hosting

I have to change url with .htaccess
.htaccess is stored in link folder.
My .htaccess file is
Options -Multiviews
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([1-9a-z]*)$ index.php\?u=$1 [L]
when i open this
'http://example.com/link/index.php?u=3ujkzf'
url it works.
But when I open
'http://example.com/link/3ujkzf' short link
I got default godaddy hosting error page.
Please Help..
Thank you for Reading..
If your project is located in the link folder, you need to include that:
RewriteRule ^link/([1-9a-z]*)$ /link/index.php?u=$1 [L]
By the way, you don't need to escape the question mark in the second part of the rewrite rule
try adding RewriteBase /
just below RewiteEngine On

Categories