.htaccess file and clean Urls problem - .htaccess

I've been using the same .htaccess file to remove the .php extension in my sites. I can't seem to figure out what doesn't work this time. Its a new hosting provider I registered with.I tried making a simple redirect to SO to see if the file was getting parsed,It does. I read the whole Apache Mod_rewrite book and understand what the file does but there's something I'm missing.Thanks in advance for the help.here's the file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteBase /
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.+) index.php [L]
Btw It's in the public_html folder which shouldn't make a difference.

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^page-name\.html$ page-name.php [T=application/x-httpd-php,L]

Related

htaccess for SEO friendly urls

So for two days I can not understand why this won't work...:
Options -Indexes
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^advice/([a-zA-Z]+)/([0-9]+)/$ advice.php?advice=$1&id=$2
Obviously .htaccess is allowed since I am not able to directory open folders, but why doesn't the link work?
Try turning off multiviews so the server doesn't try and search for that as a file. In addition add the conditions so that it knows it's not looking for a real file or directory it's trying to serve and make the trailing slash optional.
Options -Indexes +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^advice/([a-zA-Z]+)/([0-9]+)/?$ /advice.php?advice=$1&id=$2 [L]
Does your RewriteRule redirect to an existing file?
Try this, it works for me
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /test2/test.php
http://example.com/test2/.htaccess shows the location of the .htaccess file
http://example.com/test2/test.php is a direct link
http://example.com/test2/testX4XX opens the same test.php file using rewrite

Rewriting url's with .htaccess

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]

Codeigniter .htaccess not ignoring directories

I have a website built on codeigniter and am trying to get the PP IPN working with it. I have looked at a few CI specific libraries, but want to have a stand alone IPN file.
Basically, I have CI installed in the website root and I have another directory 'pp', also in the root.
I'm trying to test the IPN using Paypal's sandbox, but it's returning a 404, I also can't access the file directly.
Here is my .htaccess file:
XSendFile on
Options -Indexes
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
### Canonicalize codeigniter URLs
RewriteRule ^(index(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond %{HTTP_HOST} !^(www) [NC]
RewriteRule ^(.*)$ http://www.mysite.net/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|pp|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
</IfModule>
Here's hoping it's something really obvious!
Thanks,
Ryan
If the pp directory exists, you could just put an htaccess file in that directory and just have:
RewriteEngine On
in it by itself, and any rules in the main htaccess file would get ignored. If your paypal stuff already has rewrite rules in an htaccess file in the pp directory, you may want to look into those rules as the cause of the 404.
Do you have mod_rewrite.c enabled. If not, that .htaccess will always give 404. (Sorry I couldn't make this a comment, don't have the rep).

Zend App is not working after deployment. Can access only the homepage

I can access the homepage and can get the data from the database. There everything seems OK. But when I try to go to another page from my application I am redirected to 404 error page. The URL which is showing at the bottom left corner on my browser when hover the link seems ok. It is as should be.
I tried to change the .htaccess file on the server from:
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /
To:
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
But it fails again. Tried different combinations. For example change RewriteBase / to RewriteBase /projectname/public/ or RewriteBase /projectname/. Still no success.
Of course, I am not sure if the .htaccess is the problem. May be something different but I have no idea what...
On localhost the application is working and everything is OK there.
Edit: After several changes that I try I finally get it working.
Here is the solution:
I leaved server's .htaccess file as is. So it has only RewriteBase / on it.
Then on the first line of my .htaccess file (which is in the projectname/public folder) I added this:
RewriteBase /projectname/public
Now everything is working.
Solution
Leave server's .htaccess file as is. So there is only RewriteBase / in it.
Then on the first line of application's .htaccess file (which is in the projectname/public folder) add this line:
RewriteBase /projectname/public
Your domain name (your url) has to point to /projectname/public/ and you won't need to add anything in your .htaccess file.
As an example, here is my own .htaccess file (generated when creating my project via Zend_Tool). I need no RewriteBase ! :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
SetEnv APPLICATION_ENV development

mod_rewrite enabled but does not work properly

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]

Resources