user1117873
user1117873

Reputation: 31

mod rewrite troubles

I want to use modrewrite to give me clean urls like:

http://www.mydomain.com/about/

to be:

http://www.mydomain.com/index.php?page=about

And to go three layers in. I wrote this but its not working at all:

RewriteRule ^([^/\.]+)/?$ /index.php?page=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?section=$1&page=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?section=$1&subsection=$2&page=$3 [L]

I tested by adding print_r($_GET); and its empty when I go to

mydomain.com/about/

Edit, got it working. Stupid me i didnt need the "/" above before index.php.

However, now it will not show me my css/images. I added this but its still not working.

RewriteRule \.(css|jpe?g|gif|png)$ - [L]

What it is doing is appending the url parameters onto the image requests as such:

/page/images/bg.jpg

rather than:

/images/bg.jpg

Any ideas?

Upvotes: 1

Views: 64

Answers (1)

anubhava
anubhava

Reputation: 786091

Replace your existing with this:

# If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
# If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l 
# don't do anything
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?section=$1&subsection=$2&page=$3 [L,QSA]

RewriteRule ^([^/]+)/([^/]+)/?$ index.php?section=$1&page=$2 [L,QSA]

RewriteRule ^([^/]+)/?$ index.php?page=$1 [L,QSA]

Upvotes: 1

Related Questions