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.
Related
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)?
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.
RewriteEngine on
Options +FollowSymlinks
RewriteRule ^index\.html$ index.php [L]
RewriteRule ^gallery/([0-9]+)/([a-zA-Z0-9-_]+)/$ gallery.php?pid=$1&urln=$2 [L]
On localhost pid=$1 is working perfectly fine but on server (OVH) I get an empty value. The url is working fine, I reach gallery.php
Thanks for your help !
Most likely your server has MultiViews option enabled. Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.
Try this:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteRule ^index\.html$ index.php [L,NC]
RewriteRule ^gallery/([0-9]+)/([\w-]+)/$ gallery.php?pid=$1&urln=$2 [L,QSA]
I'm trying to set up a URL Rewrite for my website, hosted on 1&1.
Here is my .htaccess on root directory ( ./ )
AddHandler x-mapp-php6 .html .htm
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^404$ /404.html [L]
ErrorDocument 404 /404
RewriteRule ^login$ /login.html [L]
RewriteRule ^register$ /register.html [L]
RewriteRule ^contact$ /contact.html [L]
RewriteRule ^admin$ /admin.html [L]
RewriteRule ^admin/user$ /administration/user.html [L]
RewriteRule ^admin/user/p/([0-9]+)$ /administration/user.html?p=$1 [L]
There is something strange with it :
if I go to website.com/login it works well (/login.html)
if I go to website.com/admin it works well (/admin.html)
if I go to website.com/admin/user it goes to /admin.html instead of /administration/user.html (like if I
tried website.com/admin)
Even if I change the order or if I delete the line RewriteRule ^admin$ /admin.html [L] and I try to go to website.com/admin or website.com/admin/user I still have the same page (/admin.html) like if the url rewrite was in cache or something.
Anyone has a clue?
This is most likely due to enabling of MultiViews on your Apache host. Disable it by using this line on top of your .htaccess:
Options -MultiViews
Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.
I have .asp files re-writing themselves to .php files using htaccess and a rewrite rule on another site. it works fine but I am trying to do the same on my other site with one URL and it doesn't work. both have mod_rewrite enabled and on similar servers. (Apache v3.22.17 rev9999 / PHP v5.4.21)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.+).(asp)$ $1.php [L]
</IfModule>
this is the full htaccess code.. can you see anything wrong with this?
I'm not really good with mod_rewrite however have you tried this:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.+).(asp)$ $1.php [L]