skip to Main Content

I got an issue when try to access GET variable in PHP while using .htaccess file to rewrite the url in SEO friendly style.

Using an URL like www.example.com/blog/index.php?article=foo-bar I can load correctly the page, but when I use something like www.example.com/blog/article/foo-bar/ I got a redirect to the index page.

Here is my .htaccess file (note that I’m using a rule to remove the index.php in the URL)

Options +FollowSymLinks

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blog/index.php?/$1 [L]
RewriteRule ^article/([a-zA-Z0-9]+)/$ /blog/index.php?article=$1 [QSA,L]
RewriteRule ^category/([a-zA-Z0-9]+)/$ /blog/index.php?category=$1 [QSA,L]
RewriteRule ^adm/$ /blog/index.php?page=admin [QSA,L]

As replied to another post an user post me this correction, but produces an error 500, I don’t got any replies about the 500 error.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L] #This cause the error 500
RewriteRule ^article/([a-zA-Z0-9]+)/$ /blog/index.php?article=$1 [QSA,L]
RewriteRule ^category/([a-zA-Z0-9]+)/$ /blog/index.php?category=$1 [QSA,L]
RewriteRule ^adm/$ /blog/index.php?page=admin [QSA,L]
RewriteRule ^(.*)$ /blog/index.php?/$1 [L] # This too cause an error 500 in this position

By the way when i click a link refered to a category, instead of restrict only to an article in selected category i got the full list of article like the homepage.

Thanks, for helping

2

Answers


  1. You need to test with OR:

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    
    Login or Signup to reply.
  2. Try these rules:

    RewriteEngine On
    
    RewriteCond %{ENV:REDIRECT_STATUS} . [OR]
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    
    RewriteRule ^article/([w-]+)/?$ /blog/index.php?article=$1 [QSA,L,NC]
    
    RewriteRule ^category/([w-]+)/?$ /blog/index.php?category=$1 [QSA,L,NC]
    
    RewriteRule ^adm/?$ /blog/index.php?page=admin [QSA,L,NC]
    
    RewriteRule ^(.*)$ /blog/index.php?/$1 [L,QSA] 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search