mod_rewrite not working xampp (with picture) - php

I've look through the tutorials in web, and below is what I had done to test if mod_rewrite work.
First: Uncomment the mod_rewrite.so(#httpd.conf)
Second: Allowoverride -> Allowoverride all(#httpd.conf)
Third:(#.htaccess)
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^dra/?$ draft.php [NC,L]
</IfModule>
finally: if my code work the url should be rewritten to localhost/xampp/test/dra/ according to (editted from) url-rewriting for beginner
Final result: mod_rewrite not working, as you can see in the picture. Anything that I had left out?

In httpd-xammp.conf
transform
Allowoverride AuthConfig to Allowoverride All
I think it will help you

You want:
RewriteRule ^xampp/test/dra/?$ /xampp/test/draft.php [NC,L]
Or simply:
RewriteRule dra/?$ /xampp/test/draft.php [NC,L]
The RewriteRule takes from what comes after domain/ in your case it would what comes after http://127.0.0.1/ or http://localhost/.
Also this rule is not to change your draft.php, this rule you have is to allow you to access:
http://localhost/xampp/test/dra/
And have your draft.php serve it without showing it.

I was following this tutorial, and the problem for me was the suggested line:
RewriteEngine on RewriteRule .* good.html
did not work. It has to be on two separate lines:
RewriteEngine on
RewriteRule .* good.html

Related

mod_rewrite redirects don’t work as expected

I have two problems actually:
First, I’m trying to redirect several short URLs to a single page with more actions, like this:
RewriteEngine On
RewriteRule ^/login?$ ^login.php?action=login&next=$1 [L]
RewriteRule ^/reset?$ ^login.php?action=reset&next=$1 [L]
This is being written in the .conf file inside <Directory>. The problem is that the first rule gets executed, while the second doesn’t and I can’t figure why.
I also tried writing them like this:
RewriteCond %{REQUEST_URI} /login$
RewriteRule ^login.php?action=login&next=$1 [L]
RewriteCond %{REQUEST_URI} /reset$
RewriteRule ^login.php?action=reset&next=$1 [L]
I should probably mention that login.php does not reside in the root directory, but in different subdirectories.
What am I doing wrong and how can I fix it?
The second issue I have is that if I put an .htaccess file inside the root directory, the rules in the .conf file don’t get executed anymore.
Inside the .conf file I have these rules:
<Directory>
Options Indexes FollowSymLinks ExecCGI Includes MultiViews
AllowOverride All
Order allow,deny
Allow from all
RewriteEngine On
</Directory>
Why is this and how can I fix it?
Just to extend on from my comments above. Place these rules in your site root .htaccess or in httpd.conf file:
Options -MultiViews
RewriteEngine On
RewriteRule ^/?login(?:/(.*))?$ subdir1/login.php?action=login&next=$1 [L,NC,QSA]
RewriteRule ^/?reset(?:/(.*))?$ subdir1/login.php?action=reset&next=$1 [L,NC,QSA]
Option MultiViews (see http://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 /file is the URL then Apache will serve /file.html.

$_GET is always empty

My laravel application is working well on localhost, but now having moved my application to a production server, it is no longer recognizing any $_GET variables passed through the URL. My production server is set up to allow multiple laravel installations, and I am handling the rewriting with a vhost.conf file and an .htaccess file located in the laravel root.
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /international-experts/index.php/?$1 [L]
</IfModule>
vhost.conf
Alias /international-experts "/srv/http/international-experts/public"
<Directory /srv/http/international-experts>
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo Indexes
Order allow,deny
Allow from all
</Directory>
What I have done to test it is with print_r($_GET) on multiple pages. Nothing. Reading up on the problem, it sounds like MultiViews might be part of the problem. I know I'm not the only one handling multiple laravel installations on the same server... has anyone else had to tackle this problem?
Thanks
In the rewrite rule
RewriteRule ^(.*)$ /international-experts/index.php/?$1 [L]
you create a new query string with ?$1 and the default behaviour in this case is to throw away the old query string. You need to use the flag QSA, which you can remember as "query string append"
RewriteRule ^(.*)$ /international-experts/index.php/?$1 [L,QSA]
If not enough to solve your problem, it is surely a part of it.
i ran into a similar problem of $_GET[] empty. mostly because of a server issue somewhere and i had to generate my own $GET using $_SERVER['HTTP_REFERER'].
//url='http://example.com/?search=john&location=london';
$get=array();
$query=mb_split("&",parse_url($_SERVER['HTTP_REFERER'],PHP_URL_QUERY));
if(!empty($query)) foreach ($query as $qr){
$vars=mb_split('=',$qr);
$get[$vars[0]]=$vars[1];
}
var_dump($get['search']);

mod re write help - WAMP

Looking to re write a url in WAMP. I have AllowOverride Al (conf file). The mod rewrite modules is loaded. I am working on localhost
What i want to acheive is that on login the user gets redirected
localhost/propcms/xxxxxxx/
the actual address is
localhost/propcms/status.php?id=xxxxxxx
the .htaccess file has the following (and is located in localhost/propcms/ )
Options +FollowSymlinks
RewriteEngine on
RewriteBase /propcms/
RewriteRule ^propcms/([^/]*)/$ /propcms/status.php?id=$1 [L]
this is what i get....The requested URL /propcms/test121/ was not found on this server.
any ideas ??
Since you are specifying a rewritebase, you should not include it in your rewrite rule:
Try this snippet :
Options +FollowSymlinks
RewriteEngine on
RewriteBase /propcms/
RewriteRule ^([^/]*)/$ /propcms/status.php?id=$1 [L]

Creating friendly URLs with mod_rewrite in htaccess?

I have searched this forum and have done extensive google search and have not been able to figure it out. I have many links that look like:
mysite.com/example6.php?id=play-game
mysite.com/example6.php?id=watch-tv
mysite.com/example6.php?id=go-outside
I have tried lots of different code putting this in my .htaccess file:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /example6.php?id=$1 [L]
and
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^id/(.*) example6.php?id=$1
</IfModule>
and many more attempts but nothing works to get my URLS to look like this:
mysite.com/example6/play-game
mysite.com/example6/watch-tv
mysite.com/example6/go-outside
I do have mod_rewrite enabled on my server. Does anyone have any ideas?
Try this:
RewriteRule ^example6/(.*)$ example6.php?id=$1 [L]
Your first example (RewriteRule ^([^/]*)\.html$ /example6.php?id=$1 [L]) would correctly work for urls like "/play-game.html", and your second example (RewriteRule ^id/(.*) example6.php?id=$1) would correctly work for urls like "/id/play-game".

.htaccess blocking access to the site

I have an issue with htaccess that is blocking php script access.
this is the error message I receive when i load up the page:
You don't have permission to access /index.php on this server.
When i remove the .htaccess file i can access index.php with no issues.
The same .htaccess file was working fine on a different hosting that i use.
My .htaccess file (EDIT: rearranged after suggestion by toopay)
RewriteEngine On
<Files .*>
Order allow,deny
Allow from all
</Files>
Options FollowSymLinks
RewriteRule ^photos.+$ thumbs.php [L,QSA]
RewriteRule ^[a-zA-Z0-9\-_]*$ index.php [L,QSA]
RewriteRule ^[a-zA-Z0-9\-_]+\.html$ index.php [L,QSA]
I did try to set the file priviledges to 644, 755, 777 and still not working with any settings.
Could you please help me and see what i have wrong, as this is the first time it is happening and the same .htaccess file is working fine on a different domain (folder) on the same hosting.
Couldn't there be problem with <Files .*>? I think this is a wildcard pattern so you should use just <Files *>.
I managed to find the solution, the issue was really simple, i was missing a + before FollowSymLinks. Simple issue, few wasted hours to find the solution. The weirdest part is that the on the same hosting, different domain/folder it is working the same without the +... Anyway thank you for your help.
this is my final working code:
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^photos.+$ thumbs.php [L,QSA]
RewriteRule ^[a-zA-Z0-9\-_]*$ index.php [L,QSA]
RewriteRule ^[a-zA-Z0-9\-_]+\.html$ index.php [L,QSA]
The order of your htaccess, should be...
RewriteEngine On
<Files .*>
Order allow,deny
Allow from all
</Files>
Options FollowSymLinks
RewriteRule ^photos.+$ thumbs.php [L,QSA]
RewriteRule ^[a-zA-Z0-9\-_]*$ index.php [L,QSA]
RewriteRule ^[a-zA-Z0-9\-_]+\.html$ index.php [L,QSA]

Categories