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]
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)?
The PHP Nette framework, Url is not working on localhost. On the live server it is working fine but when I installed it on localhost from the latest backup from hosting server it does not work.
My .htaccess file is as:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ /www/$1 [L,NE]
</IfModule>
My Localhost URL on Wamp which the home page is working properly
http://localhost/ongoingclients/www/www/
But other urls are not working.
what does it mean that it is not working? It shows 404 from apache?
try to check that
mod_rewrite in apache is enabled
AllowOverride in apache vhost settings is set to All
The above issue is resolved by .htaccess of rule RewriteBase
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ongoingclients/www/www/
# prevents files starting with dot to be viewed by browser
RewriteRule /\.|^\. - [F]
# front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$ index.php [L]
</IfModule>
Got success, thank you.
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.
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.
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.