2
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /dir/index.php?category=$1&link=$2 [L]
RewriteCond %{REQUEST_URI} !\.[^./]+$ 
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.mydomain.com/dir/$1/$2 [R=301,L]

I'm having a problem with this one, I hope someone will help me.

www.domain.com/dir/category/

works well, but when it comes to a second variable

www.domain.com/dir/category/variable/

it doesn't work, but if I remove the last slash, it works...

EDIT----------------------------

This works fine so far.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ /dir/index.php?category=$1&link=$2 [L]


RewriteCond %{REQUEST_URI} !\.[^./]+$ 
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.omain.com/dir/$1/$2 [R=301,L]
1
  • Where is this htaccess ? is it in /dir ? Commented Aug 21, 2011 at 18:43

2 Answers 2

1

Try replacing the first RewriteRule by this one:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([^/]*)/([^/]*)/?$ /dir/index.php?category=$1&link=$2 [L]

This explicitly allows a trailing slash at the end.

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

1 Comment

Add rewrite conditions before the rule to not rewrite if the requested file exists (see my updated answer)
0

Change

RewriteRule ^([^/]*)/([^/]*)$ /dir/index.php?category=$1&link=$2 [L]

To

RewriteRule ^([^/]*)/([^/]*)([^\.css|\.js])/?$ /dir/index.php?category=$1&link=$2$3 [NC,L]

EDIT This is a massive cop out and I will hopefully update this at some point with a single line rule that does everything, but for now this will work (my brain is not working properly any more). This assumes that your JS is in a directory called 'js' and CSS is in a directory called 'css'. The order of these rules is important!

RewriteRule ^(css|js)/(.*)$ /dir/$1/$2 [L]
RewriteRule ^([^/]*)/([^/]*)/?$ /dir/index.php?category=$1&link=$2 [L]

13 Comments

What do your js/css links look like (the contents of the src/href attributes)?
nop, can't open categories and get variables.. not found. css worked but it didn't show images
Yeh I know, I have just been playing with it... I am just going to have to refresh my Regex'ing, not done any mod_rewrite this complicated for a while... I'll get back to you in 5 mins...
See latest edit. If I can work out a better solution, I will get back to you.
everything works except css and js. can't list folder content too. and yes, 'js' and 'css' are dirs
|

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.