I have a php file which is home.php
my url on localhost is
http://localhost:8888/photo/home.php
I want to remove .php from the url
so i create .htaccess file
RewriteEngine On
RewriteRule ^home?$ home.php
but i keep getting this error
The requested URL /photo/home was not found on this server.
First of all, ensure your .htaccess file is in the base directory of your project. Next, follow these htaccess rules to set up your redirect.
The .htaccess solution you might be looking for is:
RewriteEngine On
#Neither a file nor a directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^photo/home$ photo/home.php [QSA,L]
Try it like this, in your photo directory.
RewriteEngine On
# neither a file nor a directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^home$ home.php [QSA,L]
I got this problem when I put the .htaccess code in the root .htaccess. It works when I create a new .htaccess in the subdomain folder on the same level with public_html folder and fill it with the RewriteRule needed
Related
I want to re-write the following url from:
www.phcc.com/reports/caseFullDtlByCaseSno.php?case_sno=1
To
http://www.phcc.com/reports/1/caseFullDtlByCaseSno.html
For this i have written the following .htaccess file inside the reports directory which is the sub-directory of the website root:
RewriteEngine on
RewriteBase /reports/
RewriteRule ^(.*)/(\d+)\.php $1=case_sno&$2.html [NL,L]
RewriteRule ^(.*)/(\d+)\.html $1=case_sno&$2.php [L]
but it does not complete the request as i need it.
What should i do?
Try with below, I am assuming the html files are not existent.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\d]+)/([\w-]+)\.html$ $2.php?case_sno=$1 [L]
I have web project where index file is on deep folder.
Lets say my project index is on localhost/xxx/a/b/c/index.php, but I want to hide /a/b/c path become localhost/index.php.
How to code .htaccess and where I should put it?
Thank you.
Try the following in public_html/.htaccess
RewriteEngine on
#if the request is not for and existent file
RewriteCond %{REQUEST_FILENAME} !-f
#and the request is not for and existent directory
RewriteCond %{REQUEST_FILENAME} !-d
#then rewrite it to /a/b/c/request
RewriteRule ^(?:xxx/)?(.*)$ /xxx/a/b/c/$1 [NC,L]
This will internally redirect
example.com/file.php
to
example.com/a/b/c/file.php
I have a directory in my site with a bunch of temporary PHP generated PDF files.
mysite.com/crm/pdfs/
I have an .htaccess file located in the pdfs/ directory with the intention of redirecting all requests within that folder to the index.php page within that folder and include the original request in the query string. For example,
When a browser is pointed to:
mysite.com/crm/pdfs/somepdf.pdf
it should be redirected to
mysite.com/crm/pdfs/index.php?p=somepdf.pdf
Here's my current try:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
The problem with this is, when the user requests:
mysite.com/crm/pdfs/somepdf.pdf
They are instead redirected to
mysite.com/index.php
and the original request is not appended.
How can I achieve the desired result in my .htaccess that is located in the /pdfs directory?
Use this rule in your /pdfs/.htaccess:
RewriteEngine On
RewriteBase /crm/pdfs/
RewriteRule ^(.+?\.pdf)$ index.php?p=$1 [L,QSA,NC]
Let's say we have the following schema:
root/
application/
-public/
index.php
css/
img/
javascript/
...
system/
...
I was thinking that if I create an .htaccess file in the root with the following rules:
RewriteEngine On
RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ application/public/index.php?url=$1 [QSA,L]
I would be able to make other folder except public unable to be accessed. Assume index.php is the file that load all the file the application need and include and require them (with relative paths obliviously): the application is actually run in index.php and every public file such as css stylesheet, images or javascript script are in the public folder. So you, as user, cannot access the system folder because if you digit www.site.com/ it refers to root/application/public/. Am I right?
But the htaccess rule I set there does not work... If I put that htaccess in the root folder and I try to access the root folder the browser shows me the list of the file of the root folder (application and system). Why isn't it working?
I used this while ago when index.php was in the root folder:
RewriteEngine On
RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
and it worked just fine. Why isn't the new one working?
The document root of you project should be set to the /public folder.
This way that's the only folder to web-user would have access to.
Edit: for more info check the apache manual http://httpd.apache.org/docs/2.0/mod/core.html#documentroot
My initial code was right. Except for the third line which obliviously considered / a folder and made me see it instead of redirecting to application/public/.
Commenting the third line everything worked fine.
RewriteEngine On
RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ application/public/index.php?url=$1 [QSA,L]
I uploaded a project to a directory. I have a subdomain which points to this directory.
root/foo => foo.mydomain.com
When I go to foo.mydomain.com, I get the error "Internal Server Error", I'm sure this has to do with .htaccess, but I haven't got a clue where to go. Do I put the .htaccess in the root? or the folder which points to my subdomain.
So to Summarize:
I have a subdomain foo.mydomain.com, this points to a directory in my root (root/foo/index.php).
I need a .htaccess file which can resolve this error. My Current .htaccess file is here:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I know this .htaccess file is wrong, because it was what I used on my localhost, Where this project was in the root. Now I've taken it out the root, I need a working .htaccess to fix this. What do I need to edit in the above code to make my project work.
Project: root/foo/index.php <-- This is where my project is(directory called "foo")
I also have a subdomain pointing to ^^ The said directory.
Hey I too was having the same issue. Just now I fixed after trying a lot :D . Add RewriteBase :) .
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Hope it will work for you too.