Closed Thread Icon

Topic awaiting preservation: .htaccess troubles (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12914" title="Pages that link to Topic awaiting preservation: .htaccess troubles (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: .htaccess troubles <span class="small">(Page 1 of 1)</span>\

 
quisja
Paranoid (IV) Inmate

From: everywhere
Insane since: Jun 2002

posted posted 10-04-2003 21:36

I'm looking to rewrite some urls for my website, but after numerous attempts can't seem to get it working. I've read multiple articles on various websites, have a basic understanding of regex, but still it refuses to work. This is all I'm looking for:

/foo/bar/ should be mapped to /?p=foo&q=bar unless /foo/bar/ is a real directory
/foo/ should be mapped to /?p=foo unless /foo/ is a real directory
And ideally you shouldn't need to type the trailing slashes on each url...

Can anyone help me out with this? Thanks in advance...

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 10-04-2003 22:06

quisja: If foo is a directory it will write to that but you can't have either or. Going with your longer description then try:

code:
RewriteEngine  on
RewriteBase /
RewriteRule ([a-zA-Z0-9_]+)(/)?([a-zA-Z0-9_]*) /?p=$1&q=$3 [L]



Part of the trick to getting mod_rewrite right is to plan how it will be used and try and make things as simple and logical as possible. You might not be explaining what you are trying to do correctly but your description sounds confused and you are pos. asking too much of mod_rewrite. I suspect it would be possible to do what you want but it wouldn't be very efficient and you'd be better of planning it out better.

___________________
Emps

The Emperor dot org

quisja
Paranoid (IV) Inmate

From: everywhere
Insane since: Jun 2002

posted posted 10-05-2003 12:09

Thanks Emps. I've rethought a little and realised that such a catch-all solution wasn't really neccessary. Instead I've just written rules for individual sections of my site that needed it, eg.
/gallery/Paintings/ becomes /?p=gallery&q=Paintings

One thing that I still can't get working is

/gallery/Paintings/20 becoming /?p=gallery&q=paintings&start=20

This is my code currently:
RewriteEngine on
RewriteBase /
RewriteRule ^gallery/([a-zA-Z0-9_]+) /?p=gallery&q=$1 [L]
RewriteRule ^gallery/([a-zA-Z0-9_]+)/([0-9_]+) /?p=gallery&q=$1&start=$3 [L]

Any ideas?

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 10-05-2003 15:42

quisja: It depends on what you are doing really - if all the code goes through that script then that won't be a problem if some will and some won't think about using something like:

<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>RewriteRule ^(gallery

« BackwardsOnwards »

Show Forum Drop Down Menu