htaccess file hit an error - php

when i am includeing htaccess file in my project, it gives an error.
i am using php and mysql.
## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks
#
# mod_rewrite in use
RewriteEngine On
Rewritebase /xyz/
# For UI Start
### For Index page
RewriteRule ^index$ index.php [NC,L]
RewriteRule ^index/$ index.php [NC,L]
This is my htaccess file code.
i am working with WAMP.
it gives an error Internal Server Error.
Thanks

The best thing to do would be to look into the error log file, but I assume you have no access to that.
First of all then, make sure mod_rewrite is installed on the server.
Try putting only
RewriteEngine On
into the htaccess file. If that fails with a 500, mod_rewrite is turned off and you need to talk to your provider.

You need not include htaccess files. just put it in proper place. I am sure this is your first time.

Related

.htaccess rewrite on $page

It seems I am stuck. I have found answers, but I can't get them to work.
I am working on this website. I use a switch to determine what content should be visible. I use the variable $page.
The links with this method are not good for SEO so I want them to be /example instead of index.php?page=example.
I have looked at all the different answers to this on StackOverflow, but I can't get any solutions to work. There are no errors coming up and the site will show just fine, but the rewrite doesn't work.
I have tried on both my servers on servage.net and one.com
Any suggestions? :D would be much appreciated!
Try adding this to the .htaccess file in your web document root folder (often public_html or htdocs), then point your browser to example.com/somepage:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^./]+)/?$ page=$1 [L,R]
Once you are satisfied that the redirect works, you can change the R to R=301 to make it permanent.
This assumes that mod_rewrite is both installed and activated for htaccess files.
If you are not sure, to check if mod_rewrite is installed, look at the list of installed modules in the output of phpinfo();
By default, mod_rewrite is not enabled for htaccess files. If you are managing your own server, open httpd.conf
and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All

Trying to figure out htaccess issues

I'm having some issues figuring out how to use an htaccess file. I've got apache/php installed on an ubuntu system and mod_rewrite is turned on (php_info() states that it's in the list of loaded modules). The web server works, displays html and php files, so I'm happy with that.
What I'm trying to figure out now is how to use an htaccess file properly. I created a directory, /data, with an index.php file in it. All I want it to do at the moment is just display the $_REQUEST variable so I can see if things are working the way I assume they should.
Example: If I type in the following URL: localhost/data/info1/ I want the htaccess file to access localhost/data/index.php?request=info1
However, no matter what I enter in to the htaccess file, I keep getting 404 errors, and I'd like to understand why.
Here's my htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule data/(.*)$ data/index.php?request=$1 [L]
</IfModule>
I've made no changes to the config file, to activate mod_rewrite, I used the ubuntu a2enmod command so ubuntu did it for me. After that, I restarted apache.
What I can't figure out is why this doesn't work. My assumption is that there's still some sort of configuration I need to do on the server end, but I honestly don't know what. Is there any advice anyone can offer me?
Here's the fix:
RewriteRule ^data/(.*)$ data/index.php?request=$1 [L]
(You were missing a ^)
EDIT:
In the OP, you have another leading / in the URL example, in this case it'd be:
RewriteRule ^data/(.*)/$ data/index.php?request=$1 [L]

Very simple .htaccess mod_rewrite configuration gives 404

Ok, I'm starting to think that the problem is me but... ¿What's wrong here?
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule testpage\.html http://www.google.com [R] #It works
RewriteRule ^mineral/([0-9]+)/?$ ver.php?id=$1 [NC,L] #It doesn't
I have a folder called "WebX" and this .htaccess inside it along with other files from the web.
mod_rewrite is working ok according to phpinfo and everything is running on localhost.
The most courious thing is that if I type localhost/WebX/testpage.html it redirects to Google
but unfortunately for me if I type localhost/WebX/mineral/1 it gives me 404. ¿What happens?
The problem you are having is caused by RewriteBase /. Your .htaccess is in a subdirectory /WebX/, but you are telling mod_rewrite to rewrite rules as if the current directory was /. It tries to load a file ver.php in your www-root, which doesn't exist. If you have verbose error messages with what file it tried to load, you'll notice it says that it tried to load /ver.php and not /WebX/ver.php as you might expect.
The rest you are doing, most notably using a relative url instead of a / prefixed absolute url, seems correct. The correct .htaccess to use would be:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /WebX/
RewriteRule testpage\.html http://www.google.com [R] #It works
RewriteRule ^mineral/([0-9]+)/?$ ver.php?id=$1 [NC,L] #It now should work

Trouble with php mod_rewrite

i'm having some mod_rewrite problems. I am working on a rewrite simple rewrite tool that should help me with my website. but i don't know where is the problem
this is my .htaccess file:
RewriteEngine on
RewriteBase /
RewriteRule ^text\/$ text.php [L,NC]
and my phpinfo() says that i have my mod_rewrite loaded
also i have a apache hadler: AllowOverride On
so I don't know why this isn't working... can anyone tell me what else could be the problem ?
You need to add the following at the top of your .htaccess file
Options +FollowSymlinks
Also, what rewrites do is allow you to go to
http://www.mydomain.com/text
and see the content that would be generated if you actually went to
http://www.mydomain.com/text.php
rather than the other way around. So the rewrite rules are basically
RewriteRule <what-I-type-in-my-address-bar> <what-page-I-see>

RewriteRule creating 500 Internal Server Error

I have the following in my .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^directory/(.*)$ directory/index.php?id=$1
What I'm trying to achieve is this:
When the URL www.example.com/directory/10 is visited, the page www.example.com/directory/?id=10 is displayed on the browser without altering the appearance of the URL.
The above code creates a 500 Internal server error though.
Does anyone know where I'm going wrong?
Your code is guaranteed to generate 500 internal server error because it is causing infinite looping. Reason is that your matching URI pattern is: ^directory/(.*)$
Which matches your URLs before and after rewrites. And once it reaches max allowed internal rewrite limit Apache throws 500 internal server error and bails out.
Change your code to this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^directory/(.*)$ directory/index.php?id=$1 [L,QSA,NC]
Above code has an extra RewriteCond %{REQUEST_FILENAME} !-f that will make sure to disallow subsequent execution of RewriteRule after first time since /directory/index.php will be a valid file.
I have got the same issue and found that "rewrite" module is not yet enabled in my case. So I need to enable it and then restart apache server:
Enable "rewrite" module: sudo a2enmod rewrite
Then restart apache server: sudo service apache2 restart
Hope this will help anyone.
You should try adding a forward slash to the front:
RewriteRule ^/directory/(.*)$ directory/index.php?id=$1
I've been caught out with that before.
Alternatively use the RewriteLog and RewriteLogLevel to debug, and look at the Apache error and access logs for further info:
RewriteLogLevel 3
RewriteLog ${APACHE_LOG_DIR}/rewrite.log
That will leave a log file in your apache log directory. In my case that is /var/log/apache
If you are using CodeIgniter and is in error problems 500. Follow the solution.
So to delete the segment "index.php" of URLs in CodeIgniter, you need to do 2 things. The first is to edit the /system/application/config/config.php file, changing the value of index_page policy to empty:
$config['index_page'] = '';
The second step is to create a file .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
And that's it! From now on, the URLs of your site/system made with CodeIgniter will no longer have the thread (called "annoying" by some) "index.php".
Another day searching for a strange error on Apache.
Working on my Docker Apache 2.4.48 alpine container. But not in production.
Here is the difference (just a dot):
Not working on hosting provider
RewriteRule ^public/(.*)$ ./public/index.php?route=/$1 [L,QSA]
Working on hosting provider
RewriteRule ^public/(.*)$ /public/index.php?route=/$1 [L,QSA]
Just uncomment #LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
Because by default it was disabled/commented

Categories