i have problem with rewrite url in .htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteBase /web/
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..

RewriteEngine On
RewriteRule ^([^/]*)$ artist.php?artist=$1 [R]

thanks ..

This should be what you need

RewriteRule ^([a-z0-9-\s]+) artist.php?artist=$1 [L,NC,QSA]

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

<link rel="stylesheet" type="text/css" href="css/style-admin.css">

Use

<link rel="stylesheet" type="text/css" href="/web/css/style-admin.css">

Or you could write the rewrite rule for your CSS

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.

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>

I am sorry, the last piece of code will be :

<FilesMatch "\.css$">
RewriteRule ([a-z0-9-\s]+)(\.css) $1.php
</FilesMatch>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.