not rewriting .asp files using htaccess - php

I have .asp files re-writing themselves to .php files using htaccess and a rewrite rule on another site. it works fine but I am trying to do the same on my other site with one URL and it doesn't work. both have mod_rewrite enabled and on similar servers. (Apache v3.22.17 rev9999 / PHP v5.4.21)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.+).(asp)$ $1.php [L]
</IfModule>
this is the full htaccess code.. can you see anything wrong with this?

I'm not really good with mod_rewrite however have you tried this:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.+).(asp)$ $1.php [L]

Related

htaccess php GET not working

My .htaccess doesn't work with GET. It displays "news/", but once I go "news/1" or "news/1/" it doesn't work.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^/?$ index.php [NC,L]
RewriteRule ^news/$ news.php
RewriteRule ^news$ news.php
RewriteRule ^news/([a-zA-Z0-9_-]+)/$ news.php?id=$1 [L,QSA]
RewriteRule ^news/([a-zA-Z0-9_-]+)$ news.php?id=$1 [L,QSA]
My PHP is:
if(!isset($_GET["id"])){
$Article->printArticles();
}else{
$Article->printArticle($_GET["id"]);
}
But it doesn't find the $_GET["id"] but at localhost it works.
Have tried with [L,QSA], [N], [NC,L] and without any of these.
How shall the htaccess look to find the $_GET["id"]?
How shall the htaccess look to find the $_GET["id"]
This is most likely result of MultiViews option being ON on your web server.
Turn it off using this line at the top:
Options +FollowSymLinks -MultiViews
Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So if /news is the URL then Apache will serve /news.php.

mod_rewrite is not working with my urls

I am trying to make SEO friendly URLs of using apache mod_rewrite.
My normal URLs is something like this -
index.php?p=about
index.php?p=contact
index.php?p=this
My expecting SEO friendly URLs should be something similar to this -
localhost/php_advance/ch02/about
localhost/php_advance/ch02/contact
localhost/php_advance/ch02/this
I tried it with creating a .htaccess file and doing some changes to my apache httpd.conf file.
This is my .htaccess file
<ifModule mod_rewrite.c>
# Turn on the engine:
RewriteEngine on
# Set the base to this directory:
RewriteBase /php_advance/ch02/
# Redirect certain paths to index.php:
RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1
</ifModule>
And also, At the end of the httpd.conf file, I added some code like this -
<Directory "C:/wamp/www/php_advance/ch02">
AllowOverride All
</Directory>
NOTE: I am using WAMP server and Windows 07
But this coding is not working for me. Hope someone will help me out.
Thank you.
Make sure mod_rewrite is turned on. In your httpd.conf file, you should have something similar to:
LoadModule rewrite_module modules/mod_rewrite.so
Then make sure your htaccess file is in your /ch02/ directory.
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /php_advance/ch02/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /php_advance/ch02/index.php [L]
</IfModule>

Friendly URLS / URL Rewriting using .htaccess on godaddy shared server

I have been looking all over the place to find some code to work with my godaddy URL Rewriting, but no luck.
I am trying to make my website with Friendly URLS with .htaccess e.g. domain.com/company/buy/items.php?fatherID=23 ==> into ==> domain.com/23 I tried almost all codes and the best i got to is removing the .php
Sample Code:
Options +FollowSymLinks -MultiViews
Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/([0-9]+)/?$ company/items.php?fatherID=$1 [NC,L]
Does anyone have any idea with some simple code? I am on godaddys shared Linux server.
I tried to redurect 404 error codes with:
ErrorDocument 404 /domain.com/home/404error.php
but this also did not work.
Is there something I am missing?
Try this , it should be work
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^([0-9]+)$ company/items.php?fatherID=$1 [L]
</IfModule>
Godaddy is a special case. It will work surely.
DirectoryIndex index.php
AddDefaultCharset utf-8
RewriteEngine on
Options +FollowSymlinks -MultiViews -Indexes
RewriteBase /
RewriteRule ^/([0-9]+)/?$ company/items.php?fatherID=$1 [NC,L]

SEO friendly url in PHP htaccess

I use Godaddy Apache server to build my own blog, and I did some search of SEO friendly url tutorials, and applied the following code in my web root .htaccess file to transfer links like http://www.bgmemo.com/blog.php?url=2012/08/23/4-steps-to-initialize-Apache-Derby-10-9-1-0-in-Netbeans-7-1-1.html to http://www.bgmemo.com/blog/2012/08/23/4-steps-to-initialize-Apache-Derby-10-9-1-0-in-Netbeans-7-1-1.html :
RewriteEngine on
RewriteRule ^([a-zA-Z0-9-/]+).html$ blog.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+).html/$ blog.php?url=$1
But it does not work. The htaccess is working and other code in it is applied. Who can tell me what is wrong? Thanks in advance.
Try this:
RewriteEngine on
RewriteBase /
RewriteRule ^blog/([a-zA-Z0-9\-/\.]+)/?$ blog.php?url=$1 [L]
This is the correctly way for donĀ“t have problems with your .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^blog/([a-zA-Z0-9\-/\.]+)/?$ blog.php?url=$1 [L]
</IfModule>

Disable .htaccess for a directory

Im using a Framework which has this .htaccess file:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.ico)$
RewriteRule ^(.*)$ entryPoint.php [QSA]
</IfModule>
thats very good, because entryPoint.php runs everytime. But I have a PhpBB forum, placed in SITEROOT/forum directory. It would be the best that in this /forum directory to .htaccess be ignored. How to set a rule to be ignored in a directory?
I'm a bit rusty with my rewrite rules but,
RewriteCond $1 !^/forum
Should work.

Categories