0

I'm having trouble with htaccess because I would like to have my URLs SEO friendly. And that's all good but I can't go on the URL without using .php

My URL is:

http://rasolutions.eu/blogitem?id=3

And I want it to be:

http://rasolutions.eu/blogitem/3/

I've searched online and I've written code that made it work, the only problem is that I can't go to the URL unless I use .php My htaccess code is this(I'm a noob if it comes to htaccess):

ErrorDocument 404 /404.php

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

# WWW to not WWW.
RewriteCond %{HTTP_HOST} ^www\.rasolutions\.eu$
RewriteRule ^/?$ "http\:\/\/rasolutions\.eu\/" [R=301,L]

# No PERL access/
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* – [F,L]

RewriteEngine On
RewriteRule    ^blogitem/([0-9]+)/$    blogitem.php?id=$1    [NC,L]
RewriteEngine On
RewriteRule    ^blog/([0-9]+)/$    blog.php?page=$1    [NC,L]

# Home redirect.
DirectoryIndex home.php

Thank you very much for helping! Sorry for the bad English, it isn't my mother tongue.

1
  • You can remove the second and third RewriteEngine On as it is turned on already. Commented Apr 19, 2014 at 23:44

2 Answers 2

1

Try this:

ErrorDocument 404 /404.php

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

# WWW to not WWW.
RewriteCond %{HTTP_HOST} ^www\.rasolutions\.eu$
RewriteRule ^/?$ "http\:\/\/rasolutions\.eu\/" [R=301,L]

# No PERL access/
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* – [F,L]

RewriteEngine On
RewriteRule    ^blogitem/([0-9]+)/$    blogitem.php?id=$1    [NC,L]
RewriteEngine On
RewriteRule    ^blog/([0-9]+)/$    blog.php?page=$1    [NC,L]

# Home redirect.
DirectoryIndex home.php

Multiviews should allow Apache to search out a nearest match, e.g. without the ".php" extension.

Best of luck!

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for that quick response. It almost works, the only problem is that blog/1/ works but blogitem/1/ doesn't. I don't know why. If I'm going to rasolutions.eu/blogitem/6 it will send me to rasolutions.eu/blogitem/6/blog
1

Have it like this:

ErrorDocument 404 /404.php
# Home redirect.
DirectoryIndex home.php
Options -MultiViews

RewriteEngine On

# No PERL access/
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* – [F,L]

# WWW to not WWW.
RewriteCond %{HTTP_HOST} ^www\.rasolutions\.eu$
RewriteRule ^ http://rasolutions.eu%{REQUEST_URI} [R=301,L,NE]

RewriteRule ^blogitem/([0-9]+)/?$ blogitem.php?id=$1 [NC,L,QSA]
RewriteRule ^blog/([0-9]+)/?$  blog.php?page=$1 [NC,L,QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [L]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.