1

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 2

3

You need to test with OR:

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
Sign up to request clarification or add additional context in comments.

Comments

1

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] 

9 Comments

Can you check Apache error.log and see what the error is? Where is this .htaccess located?
my error.log located in var/logs/apache2 is blank, i've tried to set the loglevel to info in apache config but still blank
In the conf file i got this line ErrorLog ${APACHE_LOG_DIR}/error.log I'm using Cloud9 so maybe the vfs is configured to store these log in other path?
Ok no 500 errors, but still not working, every link send me to the home. You can try here aem-new-andreaem-dev.c9users.io/blog
Is your .htaccess located inside blog folder? If yes can you try my updated rules
|

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.