mbtaylor Posted February 19, 2007 Share Posted February 19, 2007 Hi everyone I use a regex that I KNOW should be better but I cant seem to get the right syntax. Here is what I use: RewriteBase / RewriteCond %{REQUEST_URI} (\.htm) RewriteRule ^([^/]+)?/?([^/]+)?/?([^/]+)?/?([^/]*)$ index.php What it does is basically send any HTML page to index.php - which then gets dealt with using the url as variables for content lookup etc. What I am wondering is how I repeat the middle section ?/?([^/]+) so that it will do any url lengh as currently it does 3 levels e.g: http://www.mydomain.com/dir1/dir2/dir3/somepage.htm Cheers! Mark Quote Link to comment Share on other sites More sharing options...
effigy Posted February 19, 2007 Share Posted February 19, 2007 Try this: ^(?:[^/]+/?)+$ Quote Link to comment Share on other sites More sharing options...
mbtaylor Posted February 19, 2007 Author Share Posted February 19, 2007 Hmmm no that didnt work but cheers. The reason why it didnt work was because FCKEditor (inline html editor) loads the page content into itself when using your modified regex, whereas it doesnt with mine. Otherwise it would have worked... I dont know whats going on there. Quote Link to comment Share on other sites More sharing options...
effigy Posted February 19, 2007 Share Posted February 19, 2007 What is the URL being sent to rewrite and the result? Quote Link to comment Share on other sites More sharing options...
mbtaylor Posted February 19, 2007 Author Share Posted February 19, 2007 For example http://www.mysite.com/home.htm http://www.mysite.com/somedir/blah.htm http://www.mysite.com/somedir/anotherdir/blah.htm The url can be anything, any depth etc. It all gets sent to index.php. None of the urls are 'real' all content is dynamic and stored in the database. So I guess the real url would be something like http://www.mysite.com/1/2/3 Quote Link to comment Share on other sites More sharing options...
effigy Posted February 19, 2007 Share Posted February 19, 2007 I'm not sure why the previous expression didn't work. The URIs from your example would be.. home.htm somedir/blah.htm somedir/anotherdir/blah.htm ...which match in code. Right? If you want everything rewritten except links to index itself, you can try ^(?!index\.php), assuming that negative look aheads work in mod_rewrite. Quote Link to comment Share on other sites More sharing options...
mbtaylor Posted February 19, 2007 Author Share Posted February 19, 2007 Seems to be a problem with FCKEditor parsing the page as I agree your regex does work otherwise, as do others I have used! Does the same with TinyMCE too... its a strange one. Quote Link to comment Share on other sites More sharing options...
effigy Posted February 19, 2007 Share Posted February 19, 2007 I don't know what else to suggest--I know nothing about those editors and how they function. How is your rewrite expression working? It's interesting that everything is optional.... Quote Link to comment Share on other sites More sharing options...
mbtaylor Posted February 20, 2007 Author Share Posted February 20, 2007 The regular expression just sends ALL urls that come to the domain to index.php for processing. Its part of a CMS framework I wrote... The inline editors seem to load the whole page html into their modified textarea, I am guessing being more specific with the regular expression is what is preventing the editor loading the page html. I guess they might be replacing the textarea with inline iframe dynamically with javascript. Then maybe the iframe is loading the page content when it shouldnt be. That doesnt happen with my current regex, but it does if I use varients - its something that has bothered me for quite a while! An easy solution would be to make the admin sections not use mod_rewrite For example, currently the admin page would be say: http://www.someclientsite.co.uk/admin.htm That admin.htm doesnt exist, and is really database content being pulled from a) the menu table and b) the content table. The admin.htm is matched to a pageID and the appropriate xhtml content displayed along with whatever code modules etc that relate (admin ones in this case). All page urls are really just virtual urls and are instead of doing something like: http://www.clientsite.co.uk/index.php?pageID=123 etc. If I was to use another specific php page like admin.php (only .htm pages use mod_rewrite in the condition) then I would be fine, but then, that would mean changing system programming Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.