Trouble with php mod_rewrite - php

i'm having some mod_rewrite problems. I am working on a rewrite simple rewrite tool that should help me with my website. but i don't know where is the problem
this is my .htaccess file:
RewriteEngine on
RewriteBase /
RewriteRule ^text\/$ text.php [L,NC]
and my phpinfo() says that i have my mod_rewrite loaded
also i have a apache hadler: AllowOverride On
so I don't know why this isn't working... can anyone tell me what else could be the problem ?

You need to add the following at the top of your .htaccess file
Options +FollowSymlinks
Also, what rewrites do is allow you to go to
http://www.mydomain.com/text
and see the content that would be generated if you actually went to
http://www.mydomain.com/text.php
rather than the other way around. So the rewrite rules are basically
RewriteRule <what-I-type-in-my-address-bar> <what-page-I-see>

Related

URL Rewriting and GET values

I know there are lots of answer about this, but I can't understand why it does not work for me.
I want every URL like :
http://mywebsite.com/campagne/blabla
to be redirected to
http://mywebsite.com/campagne.php?c=blabla
Here is my .htaccess file:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule campagne/(.+)$ campagne.php?c=$1 [QSA,L] [L]
The URL is redirected to campagne.php but $_GET['c'] is not sent.
Can you help me? I cannot find what is wrong? It works on my local server but not online.
This is due to enabling of MultiViews option in your Apache. Place this line on top of your .htaccess to turn it off:
Options -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 /file can be in URL but it will serve /file.php.

Cant redirect my URL with htaccess

I am using WAMP and my url is localhost/hotel/hotels.php?id=21
Using rewrite rule as follow,
Options +FollowSymLinks
RewriteEngine on
RewriteRule hotels/id/(.*)/ hotels.php?id=$1
RewriteRule hotels/id/(.*) hotels.php?id=$1
But nothing happens..
My mod_rewrite is on and also changes done in httpd.conf file.
Please give me a suggestion to handle the issue?
You must use flags for your RewriteRule. You can change it as follow
RewriteEngine on
RewriteRule ^hotels/id/([\d]+)/?$ hotels.php?id=$1 [NC,L]
You can call your pages from
localhost/hotel/hotels/id/12
If your .htaccess file is located in localhost/hotel .

apache rewrite rule not working...trying to combine css and javascript

using php5, apache2.2
I'm trying to combine my css and javascript files into one file as per this tutorial:
http://rakaz.nl/2006/12/make-your-pages-load-faster-by-combining-and-compressing-javascript-and-css-files.html
I don't think the .htaccess rewrite is working right. Here's my .htaccess file:
<IfModule mod_rewrite.c>
RewriteRule ^css/(.*\.css) combine.php?type=css&files=$1
RewriteRule ^javascript/(.*\.js) combine.php?type=javascript&files=$1
</IfModule>
I've tried exactly what was put in the tutorial for the .htaccess, but got a "forbidden" error, so the above is the only thing I got to work and at least not throw an error.
The webpage loads all the content, but just doesn't load the .css, or javascript. I put some debugging inside the "combine.php" page to see if that page even gets called and I get nothing. So I'm thinking that the rewriterule is wrong...but I don't know how to fix it.
Here's how I include it into the html:
<link rel="stylesheet" type="text/css" href="http://somewhere.com/css/layout_2col.css,general.css" />
There are more than 100 posts of people saying it worked...i'm just not one of them.
Can anyone help? Thanks.
#Ronedog: Try without IfModule --
RewriteEngine On
RewriteBase /
RewriteRule ^css/(.*\.css) /combine.php?type=css&files=$1
RewriteRule ^javascript/(.*\.js) /combine.php?type=javascript&files=$1
The Tag <IfModule mod_rewrite.c> only works in the apache-configuration.
In your .htaccess file you have to start with
RewriteEngine On
RewriteBase /
followed by your conditions.
The hole block:
RewriteEngine On
RewriteBase /
RewriteRule ^css/(.*\.css) combine.php?type=css&files=$1
RewriteRule ^javascript/(.*\.js) combine.php?type=javascript&files=$1
I found the solution to the problem at this link: http://www.issociate.de/board/post/294029/RewriteEngine_causes_403_Forbidden_error.html
The freeBSD directory inside the httpd.conf needed to have: "Options +FollowSymLinks"...once i added this the forbidden error went away and all worked like it was suppossed to.
Thanks to everyone who helped me troubleshoot.

mod_rewrite to serve a new version of existing files

I have just made a central dynamic script to replace a messy folder full of static files. However, I would like to preserve the old URL's without having to delete those files. Let me give you an example:
I have the following files:
/oldpages/projekt1/index.html
/oldpages/projekt2/index.html
/oldpages/projekt3/index.html
The actual new urls are:
/newscript/script.php?name=projekt1
/newscript/script.php?name=projekt2
/newscript/script.php?name=projekt3
The rewrite rule is:
Options -MultiViews -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^oldpages/([A-Za-z0-9_\-]+)/(index.html)?$ /newscript/script.php?name=$1 [L,QSA]
However, whenever I try to access http://mydomain.com/oldpages/projekt3/index.html it just keeps giving back the old files. After googling, everyone said that multiviews may be the culprit, but apparently, that's not fixing it.
The rule works if the directory doesn't exist on the server, the following works perfectly:
Options -MultiViews -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^newpages/([A-Za-z0-9_\-]+)/(index.html)?$ /newscript/script.php?name=$1 [L,QSA]
And http://mydomain.com/newpages/projekt3/index.html gets the right page.
What am I doing wrong?
Any help would be greatly appreciated.
If a .htaccess in /oldpages has RewriteEngine On, that overrides all rules in the .htaccess in /.

htaccess file hit an error

when i am includeing htaccess file in my project, it gives an error.
i am using php and mysql.
## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks
#
# mod_rewrite in use
RewriteEngine On
Rewritebase /xyz/
# For UI Start
### For Index page
RewriteRule ^index$ index.php [NC,L]
RewriteRule ^index/$ index.php [NC,L]
This is my htaccess file code.
i am working with WAMP.
it gives an error Internal Server Error.
Thanks
The best thing to do would be to look into the error log file, but I assume you have no access to that.
First of all then, make sure mod_rewrite is installed on the server.
Try putting only
RewriteEngine On
into the htaccess file. If that fails with a 500, mod_rewrite is turned off and you need to talk to your provider.
You need not include htaccess files. just put it in proper place. I am sure this is your first time.

Categories