1
RewriteRule ^([^/]*)/([^/]*)$ index.php?sayfa=$1&id=$2 [L]

i have an htaccess code like this but it breaks css, javascripts and images. something happens like this

sayfa = css

id = style.css

1
  • if i move my css and javascript files to subfolder everything allright but i dont feel it is reliable solution Commented Mar 29, 2017 at 23:26

2 Answers 2

3

I would suggest just checking if the file exists using a rewrite condition:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)$ index.php?sayfa=$1&id=$2 [L]

This essentially says, if the requested filename does not actually exist on disk and is not a directory that exists on disk, then try to apply the rule.

Sign up to request clarification or add additional context in comments.

1 Comment

this answer is better thank u so much it is solved my all problems
1

Use a condition before that rule to confirm the request isn't for js or css files.

RewriteCond %{THE_REQUEST} !(?:css|js)$
RewriteRule ^([^/]*)/([^/]*)$ index.php?sayfa=$1&id=$2 [L]

Regex demo: https://regex101.com/r/7WPKGh/1/

The ?: is a non-capture group. The | are alternations. The $ is the end of the string.

For jpeg, jpg, gif, and pngs it could be updated to:

RewriteCond %{THE_REQUEST} !(?:css|js|jpe?g|png|gif)$
RewriteRule ^([^/]*)/([^/]*)$ index.php?sayfa=$1&id=$2 [L]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.