1

I'm trying to make example.com/archive/?page=1 SEO friendly but every example I've tried, gives error 500. It might be because of the index.php.

Does anybody know how to make:

example.com/archive/?page=1

to look like:

example.com/archive/page/1/
6
  • What server are you using (Apache, IIS, Nginx)? If "every example gives a 500 error" then you might have something fundamentally missing on your server? Is mod_rewrite installed (Apache) for instance? Include an example you have tried. If you get a 500 error, you should look at your error log for the "real" error. "It might be because of the index.php" - What does index.php have to do with this? "SEO friendly" - Just to note, you make URLs "pretty" primarily for the user, not "SEO". Although an example such as this (pagination) is probably of no real benefit to the user anyway.
    – MrWhite
    Commented Nov 22, 2016 at 9:54
  • I have other rewriterules that are working. The latest I've tried was RewriteRule ^archive/([^/]*)/$ /archive/?page=$1 [L] which doesn't do anything. Commented Nov 22, 2016 at 10:07
  • You appear to be missing the "page" part from the pattern in that last rule? However, it should do something if the URL you type matches the pattern. Your mention of index.php suggests that you have a front controller (like WordPress uses)? The order of directives in .htaccess is important. If you add your entire .htaccess file to your question then we can get a better idea of what's going on, you might simply have a conflict with another rule.
    – MrWhite
    Commented Nov 22, 2016 at 10:40
  • So in my htaccess file, I've only put RewriteEngine on and RewriteRule ^archive/page/([^/]*)/$ /archive/?page=$1 [L] and it still dosn't work. The page is a static page with inline pagination. I have other rewiterules that work like RewriteRule ^favicon.ico static/favicon.ico [L]. Commented Nov 22, 2016 at 11:06
  • 1
    And by "doesn't work" you mean you get a 500 error? And the URL you are requesting is of the form example.com/archive/page/1/?
    – MrWhite
    Commented Nov 22, 2016 at 12:13

1 Answer 1

1

Even if there is small reconfiguration/typo-error in htaccess file, site goes down. If you have back-up of file try upload it. Always take back-up when you edit htaccess file.

*This code should work.

RewriteEngine On
RewriteRule archive/page/(.*)$ http://example.com/archive/?page=$1
4
  • This will implicitly trigger an external (302) redirect, which defeats the point of the "pretty" URL (although this would be worth a test, to see if you get a result). However, neither will this match the URL in the request - you are missing a trailing slash. And you should include a start of string anchor (otherwise you could match too much).
    – MrWhite
    Commented Nov 22, 2016 at 12:16
  • Yes.It looks I missed the trailing slash. I didn't understand external (302) redirect. I really don't know how this triggers that.
    – Suri Babu
    Commented Nov 22, 2016 at 12:33
  • 1
    If you specify an absolute URL (including scheme and hostname) in the RewriteRule substitution then mod_rewrite implicitly triggers an external redirect as opposed to an internal rewrite (despite not explicitly including the R flag). (The docs are a bit misleading in this respect as they seem to suggest that the scheme and hostname are simply stripped if they match the current scheme and hostname - this does not appear to be the case in per-directory rewrites.)
    – MrWhite
    Commented Nov 22, 2016 at 12:47
  • However, the OP (in comments) already states they have tried something like this but it still "doesn't work" - so there would seem to be something more to the puzzle?
    – MrWhite
    Commented Nov 22, 2016 at 12:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.