Error on using .htaccess - php

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.

Related

htaccess not working in my local host

I will try to be as clear as possible:
the htaccess file is located in
http://localhost:8080/trevision/.htaccess
below is whats included in htacesss
RewriteEngine On
RewriteRule ^search/$ /searchPage.php
essentially what this is trying to do redefine the default page on the search folder from index to searchPage.php
the searchPage is found in
http://localhost:8080/trevision/search/searchPage.php
I have already checked httpd.conf and its set to AllowOverride All everwhere
Any help would be appreciated.
For any clarification, let me know.
Try changing your rule's target to:
RewriteEngine On
RewriteRule ^search/$ search/searchPage.php [L]
Since the htaccess file is in /trevision/, that's where all relative paths will start from. When someone goes to /trevision/search/ the rule will match and get rewritten to /trevision/search/searchPage.php.
Alternatively, you can try adding in the htaccess file in the search folder:
DirectoryIndex searchPage.php

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.

HTML Directory looking URL

My friend recently told me that I was able to do something like
http://example.com/about/
without having to create a directory and place a index.html inside of it, like this.
http://example.com/about/index.html
How in the world do you do this? I didn't know it was even possible to do unless you created a directory and placed a index.html inside of it, anyway thanks. :)
If you use Apache as WEB server, use .htaccess for you site root directory.
Write following rule here:
DirectoryIndex index.html
Also you can use more than one file here:
DirectoryIndex index.php index.html
In this case first found will be used.
If you don't want to use .htaccess, you can setup same in Apache config file (httpd.conf):
< Directory /foo>
DirectoryIndex index.html
DirectoryIndex index.php
< /Directory>
Here /foo - root directory of your site
Servers like Nginx can allow you to rewrite URLs, so you can place your file wherever you want.
If you use Apache web server then create a file named .htaccess
and write code like below
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?load=$1 [PT,L]
If this code when you type a url like www.example.com/about its doing to open your aboutController
Write aabout in this url http://salopek.eu/content/28/create-a-simple-php-mvc-framework
If you does not use Apache or you want simple solution then then you can just create a folder named about and create a simple index.html or index.php file. Then when you type www.example.com/about
it opens your about\index.html or index.php file
I hope it helps

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]

I Can't make RewriteBase and RewriteRule to work properly

My structure is the following:
mywebsite/clubeadv/
Inside that folder I have a file called site.php which receives a parameter id.
So, the physical path would be:
mywebsite/clubeadv/site.php?id=something
But I want it to look like this:
mywebsite/clubeadv/site/something
(where 'something' is my parameter)
HOW DO I CONFIGURE THE .HTACCESS FILE?
I tried the following:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^site/(.*)$ site.php?id=$1
Any help would be appreciated.
Thank you.
Try removing the RewriteBase and placing the .htaccess inside your "clubeadv" folder. If your .htaccess is at the root within the "mywebsite" folder, then you could lave the RewriteBase but use RewriteRule clubeadv/site/(.*)$ clubeadv/site.php?id=$1
Either way, I'm pretty sure the "^site" causes it to look for mywebsite/site/something in your case.
It looks like you want:
RewriteEngine On
RewriteBase /clubeadv/
RewriteRule . site.php?id=%{REQUEST_URI}
That will handle URLs like www.<>.com/clubeadv/abc/edf as site.php?id=/abc/edf.
Apparently the problem was the server configuration. To enable .htaccess files, we had to:
Have the following module loaded:
LoadModule rewrite_module modules/mod_rewrite.so
Enable override for needed websites under 'directory' tag:
AllowOverride All
Thank you to those who answered.

Categories