1

I'm trying to write a simple blog which is working fine untill i get to the pretty links thing.

what i'm looking to do is use URLs like mysite.com/blog/this_post and pass that into the index.html file as a url parameter so index.html?blog=this_post

Been searching everywhere and found a bunch of htaccess code but most didn't work. I did find one solution that tries to work but for some reason isn't doing it correctly. (with and without the Options +FollowSymLinks part)

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^blog/(.*) /blog/index.html?blog=$1

when I use this i get /blog/index.html?blog=index.html in the url instead of keeping the /blog/this_post and porting that into the index.html as expected. Could something on the server be set incorrectly? everything else with the blog is working like a charm but so nothing wrong with the script its just getting the pretty links to work.

Looked at an older site that has wordpress and coppied over that htaccess code but it does that same thing. All the other searches on here and other sites point to the same solution above or the wordpress but for some reason it's passing index.html to the script and not the last url segment "this_post" as expected.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.html [L]
</IfModule>
# END WordPress

what should happen is the user types in

mysite.com/blog/this_post

which remains in the address bar correct? but the htaccess file pulls this_post and passes it as an argument to the index.html script. which is what the examples above should do. why it's changing the address bar to

mysite.com/blog/index.html?blog=index.html 

i'm not sure why

side note, since i got this before...yes i'm aware of using the .php extention but .html is a client ask that they're not budging on.

edit-the link for possible duplicate was one I already found and tried to get the current RewriteRule but it's still not working.

Viking NM
  • 392
  • 3
  • 17
  • 2
    Possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](https://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – Croises Oct 27 '17 at 11:30
  • Yes thank you, that was one of the links i found that lead me to the current htaccess line, it's just not working for some reason and can't figure out why – Viking NM Oct 27 '17 at 12:00

2 Answers2

0

The best way is to made something simple like this:

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^([^/]*)\.html$ index.php?blog=$1 [L]

Options -MultiViews
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

then you can do URL like:

mysite.com/this_post

what is equal to:

mysite.com/index.php?blog=this_post

Like that you can do both calls and will work fine.

Generaly you need first decide how you want your SEO URL to look like and then you need to setup .htaccess regex and rules.

NOTE: you can't use .html for GET calls. You can use .php files for your works and use $_GET['blog'] to pickup your data from URL.

Ivijan Stefan Stipić
  • 6,249
  • 6
  • 45
  • 78
  • GET works on the .html file, everything is working except for the pretty link thing. I tried this solution and get a 404 error – Viking NM Oct 27 '17 at 11:51
  • @VikingNM if you change this RewriteRule ^([^\.]+)$ $1.htm [NC,L] to RewriteRule ^([^\.]+)$ $1.html [NC,L] it works? I think the missed the "l" of "html". – Marcelo Agimóvel Oct 27 '17 at 12:07
  • Hm... is hard tell like this. Please provide your PHP code above (update your question), provide current htaccess and will see. One bug thing: -do you work on live domain or localhost and do you work in root or working in some folder? Provide please original format of URL address – Ivijan Stefan Stipić Oct 28 '17 at 07:41
0

Seem to have found the combo that works, the [NC, L] flag combo keeps giving me a crash error so i left it just [NC]. Having it in the root account directory seems to not work also so i moved into the web directory (public_html) and that works for now.

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^blog/(.*) /blog/index.html?blog=$1 [NC]

Still not sure why the L flag gives me a server crash on the pages or why having it in the root doesn't work but moving it up into the public_html folder does, is it possibly a server configuration problem that i'm overlooking?

Viking NM
  • 392
  • 3
  • 17