WebFaction
Community site: login faq

I'm rewriting my portfolio website urls by using the following code in a htaccess file,

RewriteEngine On
RewriteBase /

#remove enter code here.php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]

# remove index
RewriteRule (.*)/index$ $1/ [R=301]

# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]

# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

It all works until I want to navigate to another page from the blog-post.php page for example, let say I want to go to the about page the url becomes cgarcia.design/web/about and it should be cgarcia.design/about so the page can load properly. Now what would I need to change in the htaccess file to accommodate files within folders?

my nav structure is the following

  • work
  • about
  • resume
  • blog - posts folder - entry
  • contact

Thank you for any suggestions.

asked 03 Jul '15, 06:40

cgarcia2595
1113
accept rate: 0%

edited 03 Jul '15, 16:36

seanf
12.2k41836

Could you perhaps provide the actual URL where this is happening?

(03 Jul '15, 16:41) seanf

I see a 403 response at that URL, so I can't troubleshoot the problem you're reporting.

(06 Jul '15, 15:32) seanf

http://cgarcia2595.webfactional.com/blog-posts/thirsty-for-knowledge

Okay I was able to fix the issue, however, if you navigate let say to another page from that link, the blog-posts does not get remove from the url.

a normal url would look something like this http://cgarcia2595.webfactional.com/about

(07 Jul '15, 07:05) cgarcia2595

That's not a problem with your .htaccess - it's a problem with code or templates used to render your pages.

For example, your "about" link is coded like this:

<a href="about">about</a>

Since it's a purely relative link to "about", if you click on it while below http://cgarcia2595.webfactional.com/blog-posts/, then it will go to http://cgarcia2595.webfactional.com/blog-posts/about.

What you want is probably like this:

<a href="/about">about</a>

So, try editing the code or template that renders those links so that the links include a leading slash.

(07 Jul '15, 16:57) seanf

It works great! Thank you!

One last question if I wanted to force a trailing slash in my urls how would i change the code I have above?

(08 Jul '15, 04:00) cgarcia2595

That's a separate rewrite rule -- something like this.

(08 Jul '15, 05:24) ryans ♦♦
showing 5 of 7 show 2 more comments
Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×262
×75
×32

question asked: 03 Jul '15, 06:40

question was seen: 2,875 times

last updated: 08 Jul '15, 05:24

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM