URL Rewriting on Hostinger.fr - php

I ask your help because I would like to do soms URL rewritting.
Here is the htacess file I wrote for my site
# Do not remove this line or mod_rewrite rules and search engine friendly URLs will stop working
RewriteBase /
Options +FollowSymlinks
Options -Indexes
php_flag display_errors off
RewriteEngine on
RewriteRule ^helper/?$ index.php?action=helper [NC,L]
RewriteRule ^probabilite/?$ index.php?action=proba [NC,L]
RewriteRule ^demon/?$ index.php?action=demon [NC,L]
RewriteRule ^info/([[:digit:]]+)$ index.php?action=info&competence=$1 [NC,L,QSA]
The host I use is hostinger.fr but I don't know how to use the rewriteRules on it. (They said that it is activated and the first line (RewriteBase /) must be here)
Thanks for your help.

Related

htaccess rewrite rule knowledge

I want to rewrite the url of mysite with help of htaccess. My website url which I need to rewrite is given below.
http://getallfreedownloads.com/category.php?slug=business_directory_listing
Result needed
http://getallfreedownloads.com/business_directory_listing or http://getallfreedownloads.com/business_directory_listing/
I have used the below code for rewrite rule in my htaccess file
RewriteEngine On
RewriteRule ^([^/]*)$ /category.php?slug=$1 [L]
Please guide me what I can do to make it work fine.
Note: After adding rewrite rule I have removed the " category.php?slug= " from the a Tag
I will be thank full to you all.
try this once.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/category.php?slug(.*)$ /$1 [L,NC,R]

how to modify .htaccess file to give QUERY_STRING?

I have the below htaccess file in my website and it was working perfectly for last two years. Recently i migrated the server to a new hosting partner and seems it not working as expected. I have confirmed that the server is supporting mod_rewrite module. And i could see the [QUERY_STRING] => is null what ever URL i specify, and all the URLs are routing to the home page. Can any one tell what i need to modify. i saw a lot many answers in stackoverflow and nothing worked for me. I am just a begginer in this htaccess file.
Options +FollowSymLinks
RewriteEngine On
Options -Indexes
# REWRITING index.php AS index #
RewriteRule ^index/?$ index.php [NC]
# Route The Pages #
RewriteRule ^index/([{a-z}]+)/?$ index.php?$1 [NC,L]
RewriteRule ^index/home/([0-9]+)/?$ index.php?home&p_id=$1 [NC,L]
RewriteRule ^index/page/([{a-z}{\-\}{0-9}]+)/?$ index.php?page&show=$1 [NC,L]
RewriteRule ^index/gallery/([{image}{video}]+)/?$ index.php?gallery&type=$1 [NC,L]
RewriteRule ^index/gallery/([{image}{video}]+)/([0-9]+)/?$ index.php?gallery&type=$1&album=$2 [NC,L]
If you are matching video or image then there is no reason to have {video} as { and }will match literally{video}`.
Have your .htaccess this way:
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
# REWRITING index.php AS index #
RewriteRule ^index/?$ index.php [NC,L]
# Route The Pages #
RewriteRule ^index/([a-z]+)/?$ index.php?$1 [NC,L,QSA]
RewriteRule ^index/home/([0-9]+)/?$ index.php?home&p_id=$1 [NC,L,QSA]
RewriteRule ^index/page/([a-z0-9-]+)/?$ index.php?page&show=$1 [NC,L,QSA]
RewriteRule ^index/gallery/(image|video)/?$ index.php?gallery&type=$1 [NC,L,QSA]
RewriteRule ^index/gallery/(image|video)/([0-9]+)/?$ index.php?gallery&type=$1&album=$2 [NC,L,QSA]
Options +FollowSymLinks
RewriteEngine On
Options -Indexes
The empty query string is consistent with MultiViews being enabled (perhaps as a result of a server update). Try disabling MultiViews at the top of your .htaccess file:
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
If MultiViews is enabled then a request for /index/<something> would result in an internal subrequest to /index.php/<something> and none of your remaining directives will match.
However, you do still need to update your regex to something like what anubhava suggests, since your current regex is probably matching a lot more than you intend. But your current patterns are ambiguous. For example, what should [{a-z}{\-\}{0-9}]+ match? It looks like you perhaps intended it to be a <letter>-<digit>? However, it currently matches any combination of letters, digits and hyphens (which is how anubhava has interpreted it)?

htaccess php GET not working

My .htaccess doesn't work with GET. It displays "news/", but once I go "news/1" or "news/1/" it doesn't work.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^/?$ index.php [NC,L]
RewriteRule ^news/$ news.php
RewriteRule ^news$ news.php
RewriteRule ^news/([a-zA-Z0-9_-]+)/$ news.php?id=$1 [L,QSA]
RewriteRule ^news/([a-zA-Z0-9_-]+)$ news.php?id=$1 [L,QSA]
My PHP is:
if(!isset($_GET["id"])){
$Article->printArticles();
}else{
$Article->printArticle($_GET["id"]);
}
But it doesn't find the $_GET["id"] but at localhost it works.
Have tried with [L,QSA], [N], [NC,L] and without any of these.
How shall the htaccess look to find the $_GET["id"]?
How shall the htaccess look to find the $_GET["id"]
This is most likely result of MultiViews option being ON on your web server.
Turn it off using this line at the top:
Options +FollowSymLinks -MultiViews
Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So if /news is the URL then Apache will serve /news.php.

htaccess rewrite mod: vanity url

I've looked on SO but wasn't able to find the answer to my issue.
How can I go from :
localhost/profile.php?id=22
to:
localhost/charlie
Charlie would be the username (not the first name) here.
I also want to make sure that whether a user types in
localhost/profile.php?id=22
or
localhost/charlie
they get redirected to the appropriate profile they're looking for.
Thanks !
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+profile\.php\?id=22\s [NC]
RewriteRule ^ /charlie? [R=302,L]
RewriteRule ^charlie/?$ /profile.php?id=22 [NC,L,QSA]

Error with "RewriteEngine On" in .htaccess file on web server

RewriteEngine On
RewriteRule ^bloco/(.*)$ bloco.php?id=$1
RewriteRule ^bloco/(.*)/$ bloco.php?id=$1
My .htaccess file have that configuration, work well on my local server but at web server dont work...
local:
domain.com/bloco/590
web server:
domain.com/bloco/?id=590
right now (not working...)
Options +FollowSymLinks
Options -Indexes
RewriteEngine On
RewriteEngine On
RewriteRule ^bloco/(.*)(/?)$ /carnaval/blocosderua/bloco.php?id=$1 [NC,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1\.php
php_value allow_url_fopen 1
php_value allow_url_include 1
any help?
Modify your RewriteRule to look like this:
RewriteEngine On
RewriteRule ^bloco/(.*)(/?)$ /bloco.php?id=$1 [NC,L]
This assumes bloco.php is in your root. If it is not, you will need to specify the path to it:
RewriteRule ^bloco/(.*)(/?)$ /path/to/bloco.php?id=$1 [NC,L]
Not all hosting companies allow you to use the rewrite engine. If your getting an error try to see if it also does with only the RewriteEngine On rule. If it does I'm afraid your not allowed to use it.
As for the rules they look fine to me.
Greets Michael
You probably need to include Options +FollowSymLinks at the top of your .htaccess. Otherwise this will need to be configured in your httpd.conf.
This will basically allow you to override configuration values in your .htaccess.

Categories