Jump to content

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 :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.