1

I have some links on my website with page version and I want visitors redirected to the same page but without version number.

I got help before by {arkascha} with this code in .htaccess to affect all links, but i couldn't modify it to make exception for css and js files because visitors cannot load new version of css and js on my site because the code.

RewriteEngine on
RewriteCond %{QUERY_STRING} ^v=\d+$
RewriteRule ^ %{REQUEST_URI} [QSD,R=301,L]

example pages with version

example.com/folder/locatedpage?v=1
example.com/folder/locatedpage?v=2
example.com/folder/locatedpage?v=3

example page after the code applied through htaccess

example.com/folder/locatedpage

I want the same code above but with exception for css and js files.

1 Answer 1

1
RewriteRule ^ %{REQUEST_URI} [QSD,R=301,L]

Change the RewriteRule pattern to exclude .css and .js files. For example:

:
RewriteRule !\.(css|js)$ %{REQUEST_URI} [QSD,R=301,L]

The ! prefix negates the regex, so it is successful when it does not match. (Whereas ^ effectively matches everything.)

However, you will need to clear your browser cache before testing, since the 301 (permanent) redirect (that erroneously applied to .css and .js files) will have been cached persistently by the browser (and possibly intermediary caches). Preferably test with 302 (temporary) redirects to avoid caching issues.

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

1 Comment

that is so great, i understand now how htaccess work, thank you so much.

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.