0

I'm making a writer's website and I want to showcase some books, and then some excerpts.

I want the URLs to look like this: site.com/book/name-of-book site.com/book/name-of-book/excerpt

I managed to do the first part with this htacess:

Options +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f # Remove .php from regular pages RewriteRule ^([^\.]+)$ $1.php [NC,L] # Directory style books RewriteRule ^book/(.*)$ ./book.php?slug=$1 # Directory style books excerpts RewriteRule ^book/(.*)/excerpt$ ./book-excerpt.php?slug=$1 

My problem is the second part as it is not working, the book.php is loaded, instead of book-excerpt.php.

I've been researching on how to do this, but all solutions throughout the web seem to not work for me. What am I doing wrong? Is the first rule overriding the second? How can I fix this?

4
  • And "it is not woriking" means what ? Do you get an error? Which? Does the client hang? How long? Do you receive a falthy answer? Which? Does the universe implode? We cann guess that, you need to tell us. Commented May 22, 2018 at 11:49
  • The issue most likely is the order of processing: since the last-but-one rule always matches there is no way the last rule will ever get applied. Change their order! Commented May 22, 2018 at 11:50
  • @arkascha added some details. I tried changing the order, as you said, but the result was the same. Commented May 22, 2018 at 12:46
  • @arkascha the first rule follows the same ideal as the last-but-one. By swaping all the rules 1-2-3 to 3-2-1 I could make it work. Commented May 22, 2018 at 12:50

1 Answer 1

1

Since the rules were overriding each other, swaping all of them (1-2-3 to 3-2-1) made it work.

Options +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f # Directory style books excerpts RewriteRule ^book/(.*)/excerpt$ ./book-excerpt.php?slug=$1 # Directory style books RewriteRule ^book/(.*)$ ./book.php?slug=$1 # Remove .php from regular pages RewriteRule ^([^\.]+)$ $1.php [NC,L] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.