3

I want to make it so if /css or /images path is requested... it redirects to the /images directory from the root but for all others I want it to direct to the pages directory.

I got the second part working... this redirect all to the pages directory

RewriteEngine on
RewriteCond %{REQUEST_URI} !pages/
RewriteRule (.*) /pages/$1 [L]

but I can't get the first part to work where if the user requests /css or /images it goes to the default folder rather than having /pages in the path.

My folder structure:

css
    css files
images
    image files
pages
    index.php
    about
        index.php

2 Answers 2

1

You can add a RewriteCondition to prevent that

RewriteEngine on

RewriteCond %{REQUEST_URI} !\.(css|png|gif|jpg)$
RewriteCond %{REQUEST_URI} !pages/
RewriteRule (.*) /pages/$1 [L]
Sign up to request clarification or add additional context in comments.

Comments

0

What about this?

RewriteEngine on

RewriteCond %{REQUEST_URI} "^/css" [OR]  # if user access "/css" path
RewriteCond %{REQUEST_URI} "^/images"    # or "/images" path
RewriteRule (.*) "/images/$1" [L]        # then redirect to "/images"

RewriteRule (.*) "/pages/$1" [L]         # otherwise redirect to "/pages"

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.