944,203 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3141
  • PHP RSS
Oct 16th, 2009
0

rewrite rule not working

Expand Post »
i have problem with rewrite url in .htaccess


PHP Syntax (Toggle Plain Text)
  1. Options +FollowSymLinks
  2. RewriteEngine On
  3. RewriteBase /web/
  4. RewriteRule ^([^/]*)$ artist.php?artist=$1 [R]

i'm used [R] because i can see that mistake..
if i'm type:
http://localhost/web/djardy but it's redirect to :
http://localhost/web/artist.php?artist=artist.php
it's should be redirect to :
http://localhost/web/artist.php?artist=djardy

and i change the .htaccess code, but still not working..
PHP Syntax (Toggle Plain Text)
  1. RewriteEngine On
  2. RewriteRule ^([^/]*)$ artist.php?artist=$1 [R]

thanks ..
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
forzadraco is offline Offline
70 posts
since Mar 2008
Oct 16th, 2009
0
Re: rewrite rule not working
This should be what you need

RewriteRule ^([a-z0-9-\s]+) artist.php?artist=$1 [L,NC,QSA]
Reputation Points: 13
Solved Threads: 19
Junior Poster
jomanlk is offline Offline
103 posts
since Oct 2009
Oct 20th, 2009
0
Re: rewrite rule not working
it's still not working, http://localhost/web/ardy redirect to http://localhost/web/artist.php?artist=artist

PHP Syntax (Toggle Plain Text)
  1. Options +FollowSymLinks
  2. RewriteEngine On
  3. RewriteBase /
  4. RewriteRule ^([a-z0-9-\s]+) web/artist.php?artist=$1 [R]

and if i used that .htaccess my css site is not working properly..
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
forzadraco is offline Offline
70 posts
since Mar 2008
Oct 22nd, 2009
0
Re: rewrite rule not working
Yeah, your CSS won't work properly because the rewrite rule changes the path for requested files. If you're using relative paths this will mess up your CSS, images and JS.

You can either add rewrite rules for all your CSS and media files or you can access them using the full path starting from your webroot.

Instead of
PHP Syntax (Toggle Plain Text)
  1. <link rel="stylesheet" type="text/css" href="css/style-admin.css">
Use
PHP Syntax (Toggle Plain Text)
  1. <link rel="stylesheet" type="text/css" href="/web/css/style-admin.css">

Or you could write the rewrite rule for your CSS
PHP Syntax (Toggle Plain Text)
  1. RewriteRule ^([a-z0-9-\s]+)(\.css) web/css/$1.css

I'm not sure this is the best way (.htaccess is not my strong suite) but it works. Make sure the paths are correct for you.
Reputation Points: 13
Solved Threads: 19
Junior Poster
jomanlk is offline Offline
103 posts
since Oct 2009
Nov 13th, 2009
0
Re: rewrite rule not working
Hi,
What if I want to apply the rewrite rule to all the css files under the root directory.. I mean there can be multiple directories having css files so I cannot put web/css specifically for below:

RewriteRule ^([a-z0-9-\s]+)(\.css) web/css/$1.css

Instead, can <FilesMatch> be used to serve the purpose?

Eg, If I need to apply a rewrite rule to redirect my css file to a php file I write as below:

<FilesMatch "\.css$">
RewriteRule ^([a-z0-9-\s]+)(\.css) web/css/$1.php
</FilesMatch>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
royalrai_p is offline Offline
2 posts
since Nov 2009
Nov 13th, 2009
0
Re: rewrite rule not working
I am sorry, the last piece of code will be :

<FilesMatch "\.css$">
RewriteRule ([a-z0-9-\s]+)(\.css) $1.php
</FilesMatch>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
royalrai_p is offline Offline
2 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: question
Next Thread in PHP Forum Timeline: Show pdf file in web page





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC