About an hour ago, I Added
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*[^/])/?$
RewriteCond %{DOCUMENT_ROOT}%1.php -f
RewriteRule .+ %1.php [QSA,L]
to my .htaccess file. but It doesnt work. when I go to mywebsite.com/info or mywebsite.com/info/ it doesnt work (the page is info.php). the mod_rewrite is enabled - tested it by RewriteRule that redirected me to google from any page in my site.
I have no idea what's the problem.. maybe the code is wrong?
Thanks.
#Ron
Try changing the last two lines to this:
RewriteCond %1.php -f
RewriteRule .+ %1.php [PT]
You'll need the [PT] in order for the PHP file to be processed correctly.
GoDaddy takes about an hour to parse your newly uploaded .htaccess file. It's strange. But the file should work fine as is if you just wait.
This's what I needed for the rules to work:
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)/$ $1.php [L]
Related
I am trying to rewrite page URL's with .htaccess.
I would like to transform links like this (mysite.com/page.php -> mysite.com/page)
This is the code which I've used in previous sites with the same requirements
RewriteEngine on
RewriteCond /%{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.php
But when I try to access mysite.com/page it leeds to a 404 page where as mysite.com/page.php will show the page.
Can anyone explain if I have missed a setting somewhere? I have placed the .htaccess file in the site root dir and the permissions are set as 644.
Instead of using %{REQUEST_FILENAME} which by the way you have an unneeded / there, I suggest you to use %{DOCUMENT_ROOT}/$1\.php, here is an example:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
## To internally redirect /anything to /anything.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^([^/]+)$ $1.php [L]
Additionally on your rule you have /$ which would again cause you trouble as you want to catch /page.
You could have made it /? to make the / optional.
Your .htaccess fixed should look like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([a-z0-9_-\s]+)/?$ /$1.php [NC,L]
Okay so i'm working on creating a thing to delete images from my server. I figured out about the unlink function and have turned it into a get variable. How can I use htaccess to delete a file from my server with a url like this example.com/imagename/delete
RewriteRule ^/delete/([^/]+)$ index.php?delete=$1
I realized that this does /delete/imagename but I want the urls to be /imagename/delete. I tried the following but that didn't work.
RewriteRule ^/([^/]+)$/delete index.php?delete=$1
I know this sounds simple and easy to find on the web but I can't seem to find this!
Change your rules to
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^([^/]+)/delete/?$ index.php?delete=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.png [L]
I have a directory structure like this
/ub/
/ub/img/
/ub/inc/
Basically I want to change my img URL to it's parent directory (ub),
When i access http://localhost/ub/mypic.jpg
First, it has to check /ub/img/mypic.jpg, if exist then get that file and pass to the browser, if not then just pass it to http://localhost/ub/index.php?img=mypic.jpg with INTERNAL REDIRECTION.
Second, index.php will create mypic.jpg and store it to /ub/img/, then pass mypic.jpg to the browser.
So, whether the file is exist or not, the browser will only have http://localhost/ub/mypic.jpg as the URL
So far, i have this on my .htaccess file
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/ub/img/$1 -f
RewriteRule .+ /ub/img/$1 [L]
I have 2 days to find out the solution, but, it doesn't seem to work,
Thanks,
EDIT :
Hey, I've got this, The request to http://localhost/ub/app/file.php is already passed to index.php?uri=app/file.php as i expected,
but the request to http://localhost/ub/img/mypic.jpg is not passed to index.php?uri=img/mypic.jpg. Is there any solution?
Options -MultiViews +FollowSymLinks
RewriteEngine On
RewriteBase /ub/
RewriteCond %{REQUEST_URI} ([^/]+)$
RewriteCond %{DOCUMENT_ROOT}ub/img/%1 -f
RewriteRule ^(.+)$ img/%1 [L]
RewriteCond %{REQUEST_URI} ([^/]+)$
RewriteCond %{DOCUMENT_ROOT}ub/inc/%1 -f
RewriteRule ^(.+)$ inc/%1 [L]
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]
Try something like this (place it in .htaccess in the /ub folder):
Options +FollowSymLinks
RewriteEngine on
RewriteBase /ub/
RewriteCond %{REQUEST_URI} ([^/]+\.jpg)$
RewriteCond %{DOCUMENT_ROOT}/ub/img/%1 -f
RewriteRule .+ - [L]
RewriteRule ^(.*)$ index.php?img=$1
I'm trying to implement a REST-style URL with a mod-rewrite turned on in .htaccess. There's a bit of a kicker which is that I'm developing in a test environment (new cpanel account). Here's the .htaccess:
RewriteEngine on
#REMOVE THIS LINE ON SITE LAUNCH!
RewriteBase /~myNewAccount/
#Hide .php extensions for cleaner URLS
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Options All -Indexes
The URL I CAN use looks like this:
www.example.com/~myNewAccount/index.php/id/50
I can access the PATH_INFO here, but when I try to do this:
www.example.com/~myNewAccount/index/id/50
...I get a 500 internal server error. I've tried implementing the solution found here by Gumbo but that mucks things up.
Ideas on what might be causing this?
Try this rule:
RewriteRule ^index(/.*)?$ index.php$1 [L]
Or if you don’t want index to be in the URL path at all:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php/$0 [L]
Currently, my .htaccess file looks like htis:
IndexIgnore */*
RewriteEngine on
RewriteRule ^add /add.php
RewriteRule ^add/$ add.php
RewriteRule ^sitemap.xml /xmlsitemap.php
RewriteRule ^([^/\.]+)$ /index.php?slug=$1
RewriteRule ^([^/\.]+)/$ /index.php?slug=$1
It works fine for links as: site.com/category/
However, i would like the complete slug after site.com/. So that i can redirect site.com/category1/subcategory2/subsubcategory3 etc. There can be an unknown amount of subcategories inside a category.
I tried with request_uri but that didn't really work out.
How to do this? Thanks a bunch!
EDIT:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* slug.php?%{QUERY_STRING} [L]
this will pass URL to slug.php
ok, got it. it's simply: deleting the ^/. from the regex. i just figured that means that it has to stop at any / :) but... thx! it works now! :)