2

I have the below htaccess file in my website and it was working perfectly for last two years. Recently i migrated the server to a new hosting partner and seems it not working as expected. I have confirmed that the server is supporting mod_rewrite module. And i could see the [QUERY_STRING] => is null what ever URL i specify, and all the URLs are routing to the home page. Can any one tell what i need to modify. i saw a lot many answers in stackoverflow and nothing worked for me. I am just a begginer in this htaccess file.

Options +FollowSymLinks
RewriteEngine On
Options -Indexes

# REWRITING index.php AS index #
RewriteRule   ^index/?$   index.php  [NC]

# Route The Pages #
RewriteRule   ^index/([{a-z}]+)/?$   index.php?$1  [NC,L]

RewriteRule   ^index/home/([0-9]+)/?$   index.php?home&p_id=$1  [NC,L]
RewriteRule   ^index/page/([{a-z}{\-\}{0-9}]+)/?$   index.php?page&show=$1  [NC,L]

RewriteRule   ^index/gallery/([{image}{video}]+)/?$   index.php?gallery&type=$1  [NC,L]
RewriteRule   ^index/gallery/([{image}{video}]+)/([0-9]+)/?$   index.php?gallery&type=$1&album=$2  [NC,L]
2
  • 1
    Why do you have curly braces in your pattern? Can you tell me some URLs that are not working? Commented Aug 21, 2017 at 7:03
  • one of the url is tgmvidyaniketan.edu.in/index/gallery/image Commented Aug 21, 2017 at 8:27

2 Answers 2

1

If you are matching video or image then there is no reason to have {video} as { and }will match literally{video}`.

Have your .htaccess this way:

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On

# REWRITING index.php AS index #
RewriteRule ^index/?$ index.php [NC,L]

# Route The Pages #
RewriteRule ^index/([a-z]+)/?$ index.php?$1 [NC,L,QSA]

RewriteRule ^index/home/([0-9]+)/?$ index.php?home&p_id=$1 [NC,L,QSA]

RewriteRule ^index/page/([a-z0-9-]+)/?$ index.php?page&show=$1 [NC,L,QSA]

RewriteRule ^index/gallery/(image|video)/?$ index.php?gallery&type=$1 [NC,L,QSA]

RewriteRule ^index/gallery/(image|video)/([0-9]+)/?$ index.php?gallery&type=$1&album=$2 [NC,L,QSA]
Sign up to request clarification or add additional context in comments.

10 Comments

I was just about to post that exact same version - @Ricky you can see a demo here: htaccess.mwl.be?share=680305d4-dc3c-5d94-8016-1f890e9b0220
I have tested and its generating 500 error. My Apache version is 2.2.17
Its worked!!!! Thank you so much brother :) can you tell me what is the difference
Option MultiViews (see httpd.apache.org/docs/2.4/content-negotiation.html) is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So if /index is the URL then Apache will serve /index.php.
Thanks once again :)
|
1
Options +FollowSymLinks
RewriteEngine On
Options -Indexes

The empty query string is consistent with MultiViews being enabled (perhaps as a result of a server update). Try disabling MultiViews at the top of your .htaccess file:

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On

If MultiViews is enabled then a request for /index/<something> would result in an internal subrequest to /index.php/<something> and none of your remaining directives will match.


However, you do still need to update your regex to something like what anubhava suggests, since your current regex is probably matching a lot more than you intend. But your current patterns are ambiguous. For example, what should [{a-z}{\-\}{0-9}]+ match? It looks like you perhaps intended it to be a <letter>-<digit>? However, it currently matches any combination of letters, digits and hyphens (which is how anubhava has interpreted it)?

2 Comments

Thanks MrWhite. Options +FollowSymLinks -MultiViews did the work
You're welcome. MultiViews (part of mod_negotiation) is a common cause of conflict with mod_rewrite directives (when referring to files without the file extension).

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.