Jump to content

Newbie question - rewrites (with exceptions)


ChrisFlynn

Recommended Posts

I guess this is an ordering issue, but no amount of changing the position of [L] seems to work...

 

I'm trying to get the following behaviour on these two conditions:

 

 

1)

User visits: http://domain.com/foo

They see that in their address bar.

The page loaded is http://domain.com/page.php?value=foo

 

(To be pedantic, spaces and underscores should be replaced with hyphens in the address bar too - is this possible with [R]? I can parse the value on page.php so that's not an issue...  Value should accept hyphens, numbers, letters etc)

 

 

2)

I also have some 'real' pages which do actually exist (e.g. faq.php, index.php).

 

User visits: http://domain.com/faq  (no extension)

They see that in their address bar.

The page loaded is http://domain.com/faq.php

 

 

I'm currently achieving the latter with: RewriteRule ^([a-z]+)$ /$1.php, but this isn't working alongside the first RewriteRule ^([A-Za-z0-9-]+)/$ page.php?value=$1 [L]

 

 

Is there a dynamic way of getting both working, without hard-coding all my 'real' pages in?

Link to comment
https://forums.phpfreaks.com/topic/90711-newbie-question-rewrites-with-exceptions/
Share on other sites

I got it in the end!

 

 

# if ($1.php exists) { $1.php } else { search.php?search=$1 }

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z]+)$ /$1.php [NC,L]

RewriteRule ^([a-zA-Z]+)$ /search.php?search=$1 [NC,L]

 

 

I'm sure that wasn't worth x hours... oh well :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.