.htaccess wierd problem with rewriterule and hash - .htaccess

im adding new things to my ehop and I have some problems with rewriterule in htaccess.
Im using XAMPP as a local development tool, ale then send it to live serwer.
PHP generate links like this one:
https://kielkowski-szkolka.pl/reklamacja/c0892ce969fef9ccb1c1a8034b5e33dc19337b14
this on works on XAMPP but not on live serwer
This works on both
https://kielkowski-szkolka.pl/reklamacja/65f4c6c6686a2b248a7be2db104f3b13ea365d55
RewriteRule for this is (in .htaccess)
RewriteRule ^reklamacja/([^/\.]+)$ index.php?metoda=reklamacja_szczegoly&id=$1 [L]
why?I cant figure it out
Edit: error means that this rewriterule is skipped and another rule kicks in that redirects to home page

Related

RewriteRule works fine in a testing environment, but not on my website

I am turning crazy with this .htaccess:
I made this (and testing it out here https://htaccess.madewithlove.be/):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} my-website.com
RewriteRule ^SHORT(/.*)?$ https://%{HTTP_HOST}$1?devname=short [L,QSA]
The first rule rewrites http:// into https://. That part works both in the testing website and on my own website.
The second should change https://my-website.com/SHORT into https://my-website.com/?devname=short. That part works fine in the testing website, but not at all on my own? I don't understand why?
Extra note: The website's root folder is bound to the /www/ folder on the server, I don't know if it matters? (that's the OVH default)
Thank you for your help!
Found where my problem was!
My .htaccess file was in the root folder of the server, it needed to be in the website's folder for the paths to be relative to there (so here, in www).
Which is why CBroe was confused about why I was checking the host (since here, it's indeed unnecessary).

.htaccess rewrite rules do not work locally with XAMPP

I have been able to successfully create rewrite rules in .htaccess to rationalize the URL's of my website (thanks to SuperDuperApps as well):
RewriteEngine On
RewriteRule ^travel/([^/]*)$ ?item=travel&blog=$1 [L]
RewriteRule ^work/([^/]*)$ /?item=work&tile=$1 [L]
RewriteRule ^(about|travel|work)$ /?item=$1 [L]
This works perfect when I access the website online via the server. However, when running it locally via XAMPP I am continuously routed back to "localhost/dashboard/" (instead of "localhost/example/travel" --> "localhost/example/?item=travel" for example).
I have set AllowOverride to All and tried to include RewriteBase, but I am not getting it to work.
Does anybody know how to successfully configure/setup XAMPP or enhance the rewrite rules in such a way that it does work locally with XAMPP as well?

Alternatives to .htaccess RewriteEngine?

I have a site that I'm building at the moment, and I just noticed that, while www.mysite.com.au works fine, mysite.com.au still points to the crazydomains.com.au holding page, even though I only bought a domain name off them, and am actually hosting it on PythonAnywhere. So I created a .htaccess file to add "www." to the front of urls:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite\.com\.au$ [NC]
RewriteRule ^.*$ http://www.mysite.com.au%{REQUEST_URI} [R=301,L]
However, mysite.com.au now gets "Server Not Found" as a response (www.mysite.com.au still works fine).
I've checked to make sure the CNAME record in CrazyDomains is correct, and to the best of my knowledge it is. PythonAnywhere doesn't officially support .htaccess files, so it might be that? Is there an obvious thing that I'm missing? Are there any alternatives to .htaccess that would give me the same result?

.htaccess URL Rewrite Failing - The requested URL was not found on this server

I have a very simple rewrite rule. My entire .htaccess file is as follows:
RewriteEngine On
ReWriteRule ^([a-zA-Z0-9\-]+)$ /index.php?page=$1 [L,NC]
This works perfectly on one of my development machines running Apache. It does not work however on my other development machine running Apache (mod_rewrite listed in PHP info under apache2handler). Nor does it work on the live server, which I think is running Windows.
I have tried adding the following:
RewriteBase /
I'm no mod_rewrite wizard and I'm sure it's a very simple solution but it is eluding me currently and keep receiving a 404 not found error.
One thing that is different on the two environments in which this doesn't work, is that the site is not in the root of the URL. So for example it is http://localhost/site and www.example.com/site
I have tried various syntax adjustments in the .htaccess file, and also adding the site to the base:
RewriteBase /site
Remove the 'RewriteBase /site' and try removing the / before index.php
The slash should't be there with use of .htaccess
RewriteEngine On
ReWriteRule ^([a-zA-Z0-9\-]+)$ index.php?page=$1 [L,NC]

Rewriting URL with .htaccess local in XAMPP

My .htacces begins with
RewriteEngine on
RewriteBase /
(I tried it also without RewriteBase...)
I tried all of the following rewriting rules to rewrite the URL
index.php?page=news
to
/blog
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/blog$
index.php?page=$1 [L]
RewriteRule ^([^/]*)/blog$ /sites/blog/index.php?page=$1 [L]
RewriteRule ([a-zA-z]+)/([a-zA-z]+)/blog$ index.php?page=$1 [L]
Nothing works - no error. Mod_rewrite is installed and working. I restarted Apache and MySQL everytime I changed something in my .htaccess.
I also want to change my URLs which looks like this... index.php?page=single_news&category=release&id=9&headline=Beastie%20Boys%20III
...into: blog/release/9-Beastie-Boys-III
I am lost. Hope you can help me.
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.
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
For your first question, try this:
RewriteEngine on
RewriteRule ^/blog$ /index.php?page=news

Resources