Rewriting URL with .htaccess local in XAMPP

前端 未结 3 821
心在旅途
心在旅途 2020-12-10 23:19

My .htacces begins with

   RewriteEngine on
   RewriteBase /

(I tried it also without RewriteBase...)

I tried all of the following

相关标签:
3条回答
  • 2020-12-10 23:58

    First of all, upload your .htaccess and other files (whole project) to some working, ready hosting server. And check, if your rewriting works OK there. This will let you know, if this is problem with .htaccess or XAMPP itself. I had many strange problems with using .htaccess locally, under XAMPP, that were magically gone, after files were uploaded to Internet hosting.

    For example, I don't have working autorization using .htaccess locally, because right after I provide correct login and password I see exactly the same error message as you mentioned. As for me, I'm more than sure that this problem is purely related to incorrect interpretation of .htaccess done by XAMPP (as everything works like a charm on production server), not by some mistakes in .htaccess contents.

    I wasted (too) many hours on finding solution and left it. For right now, if I'm developing locally, I rename ".htaccess" to "htaccess", so it is ignored by XAMPP (Apache on-board of it) and re-enable it only when deploing files to production server. This approach maybe isn't to professional, but it saved me a lot of time and stress! :]

    On the other hand, if your hosting also fail with the same symptoms, then you'll know, that this is not XAMPP releated problem and you have something wrong with your syntax.

    Take a look here for a similar problem reported on StackOverflow.com, where (as I think) the cause is the same as in your issue.

    0 讨论(0)
  • 2020-12-11 00:03

    For your first question, try this:

    RewriteEngine on
    RewriteRule ^/blog$ /index.php?page=news
    
    0 讨论(0)
  • 2020-12-11 00:04

    Here's the solution to change links from http://www.domain.tld/index.php?page=blog to http://www.domain.tld/blog is:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^\w+$ index.php?page=$0 [L]
    RewriteCond %{THE_REQUEST} index\.php
    RewriteCond %{QUERY_STRING} ^page=(\w+)$
    RewriteRule ^index\.php$ /%1? [R=301,L]
    

    and for links like: http://www.domain.tld/index.php?page=single_news&id=1&headline=This%20Is%20A%Headline

    the solution is:

    RewriteRule ^blog/(\d+)-([\w-]+)$ index.php?page=single_news&id=$1&headline=$2
    

    After using this code, links looks like this: http://www.domain.tld/blog/2-this-is-a-headline

    0 讨论(0)
提交回复
热议问题