.htaccess rewrite rules do not work locally with XAMPP - .htaccess

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?

Related

.htaccess wierd problem with rewriterule and hash

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

resolving index.php issue at url laravel htaccess

I know this question is asked alot and there are alot of answers on "how to resolve index.php issue in laravel".
However, I tried multiple ways in order to solve it from .htaccess on live dedicated server with WebsitePanel in order to remove index.php from URL. I tried a couple of ways however let me describe the issue here, index.php not only have changed the url, but also some of the css and javascript stuff are not loaded as well while most of them are loaded, CSS seems pretty fine but fonts are also changed.
It was working well at a shared host but here in a dedicated host it has alot of problems.
Is there a .htaccess code to solve this issue? and does index.php affects on CSS and is it normal?
my current htaccess is as follow:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /index.php [L]
</IfModule>
You don't need to modify index.php or .htaccess. If you did this, revert to original files.
To remove index.php or public from URLs, you need to setup virtual host for Laravel project (there are instructions both for nginx and apache).
After that restart web server.
This is the most common problem in Laravel. When you upload your code to a webserver, your page will be in
www.web-something.com/index.php
So there are 2 things you should do,
1.Change the .htaccess file and also
2.Change the Virtual Host Settings in your server. Link :for setting up a virtual host in apache
After this you will be able to visit the directory just fine. Also about the CSS , problem , Its probably because of the virtual host settings. Itll get fixed up once you point everything to the right directory.
For IIS Windows Server, the .htaccess needs to be translated to web.config and this works like a charm.
here is the link:
How to enable modrewrite on IIS Web Server
In case Someone needed this in future!

Remote site not working on local server

So I'm setting up a local environment for testing and development. We use CodeIgniter as our framework.
But when I copy the whole server to the local server (I have XAMPP), and navigate to the root, all I see is a directory structure - it doesn't display anything at all that I would expect to see from the website.
I spent 4+ hours (over several days) trying every .htaccess and httpd.conf suggestion I could find on Google, stackoverflow, these forums, and more. I am able to get a 500 server error when adding garbage to the .htaccess file, so I know it's being processed. But I think my problem is possibly unrelated to the .htaccess file settings. (I don't really care if index.php shows up on the URL bar locally.)
There is no index.php on our server's root (again, our site is built with CodeIgniter). Nor anywhere else in the site's directory structure, (except /application/views/user/template/original). When I access the site live, in the URL bar it pulls up the domain name followed by: "/user/login". Looking into the /application/views/user folder shows a login_view.php, but when I try to access it directly, I get an Access Forbidden 403 error.
Per this solution, I also tried changing the DocumentRoot (in C:\xampp\apache\conf\http.conf) from "C:/xampp/htdocs" to "C:/xampp/htdocs/othersites/mysite" Same result.
How is the site loading remotely, but not locally?
Check your base_url in config.php
Here is working .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myproject
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
It turns out, for some reason, the site's root index.php wasn't in the git repo that I cloned from. I have that now, along with another (different) .htaccess file.
After changing the base_url in application\config\config.php to my localhost variant, it's working!
If I ever figure out why they didn't have index.php in that repo, I'll let you all know...

.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]

url rewriting and htaccess rule

I have rewritten a rule for URL rewriting but when i try to access the website admin panel, server shows me 404 error whereas front-end working with rewriting rule.
following rule are written
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
for admin panel
RewriteRule ^admin/page/([a-zA-Z0-9_-]+)\.html$ admin/page.php?page=$1
RewriteRule ^admin/page/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/(.*)$ admin/page.php?page=$1&$2=$3
For frontend
RewriteRule ^(.*)\.html$ $1.php [nc]
Though for front-end rule working fine and i can access the website using www.blabla.com/index.html. Written rule automatically convert the .php file into .html
Moreover these rule are working fine in my localhost and UAT server but on production server these rules do not work.
Any one can suggest what wrong i am doing or is there something with .htaccess or mod_rewrite where i can do some tweaks.
Suggest please.....

Resources