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.
Related
I want to change the URL from:
http://localhost/rootdirectory/portfolio/project-1.php
To:
http://localhost/rootdirectory/project-1
I have used below code currently but it's not working
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^portfolio/(.*)$ /$1 [L,NC,R=301]
This code is rewriting my URL as http://localhost/project-1 instead of
http://localhost/rootdirectory/project-1.
This code is rewriting my URL as http://localhost/project-1 instead of http://localhost/rootdirectory/project-1.
The code you posted is "redirecting", not "rewriting", the URL from /portfolio/<project> to /<project>.
From your URL example it looks like you should instead be rewriting the URL from /rootdirectory/<project> to /rootdirectory/portfolio/<project>.php (assuming you have already changed the URL in your application). If the .htaccess file is located at /rootdirectory/.htaccess (as stated in comments) then you would need something like the following instead:
RewriteRule ^([^./]+)$ portfolio/$1.php [L]
And remove the RewriteBase / directive altogether.
go to the folder that contains all the files for your site.
form your cpanel copy all the files to your Public_html folder.
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.
i would like to use .htaccess to rewrite every subfolder or page existing or non existing to a specific subfolder. For example www.domain.com/idontexist to redirect to www.domain.com/mainfolder. Basically all requests should to to /mainfolder and return a status of 200.
Thanks
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule !mainfolder /mainfolder [L,NC]
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]
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