Htaccess file work only in a project - php

I am using the same code, but it work only on first project.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?pg=$1 [QSA,L]

Related

htaccess RewriteRule also runs functions on other redirect page

When I go to my first url, example: website.be/festivalName/eventName then te script on the url, website.be/festivalName, runs.
What am I doing wrong?
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ views/festivals/index.view.php?organisation=$1&festival=$2&event=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ views/festivals/index.view.php?organisation=$1&festival=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ views/organisations/index.view.php?organisation=$1 [L]

.htaccess Rewrite rule conflict with other file

i have made a .htaccess file but a problem occurs is that conflicting with other file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^f9/([^/\.]+)?$ footer_arts.php?page=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^f10/([^/\.]+)?$ footer_bus.php?page=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^f11/([^/\.]+)?$ footer_cely.php?page=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^f12/([^/\.]+)?$ footer_com.php?page=$1 [QSA,L]
RewriteRule ^f13/([0-9]+)$ footer_edu.php?page=$1
when i open www.example.com/f9/1 its open perfectly , but when i open www.example.com/f10/1 or www.example.com/f11/1 it shows another page which is in my htaccess file just like f13/1, how can i prevent this conflicting and open correct page
Try your code this way.
RewriteEngine On
#if the request is a real file or directory, do nothing otherwise process one of the rules below.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^f9/([^/]+)/?$ footer_arts.php?page=$1 [QSA,L]
RewriteRule ^f10/([^/]+)/?$ footer_bus.php?page=$1 [QSA,L]
RewriteRule ^f11/([^/]+)/?$ footer_cely.php?page=$1 [QSA,L]
RewriteRule ^f12/([^/]+)/?$ footer_com.php?page=$1 [QSA,L]
RewriteRule ^f13/([0-9]+)/?$ footer_edu.php?page=$1 [QSA,L]

Apache: cannot rewrite sitemap.xml as sitemap.php

I have the following .htaccess file in the root (htdocs/johndoe) of my web document tree where index.php is found:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?lang=$1&menu1=$2&menu2=$3 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?lang=$1&menu1=$2 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?lang=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule sitemap.xml sitemap.php
Not sure what I am doing wrong, but when I access:
http://localhost/johndoe/sitemap.xml
it just loads my index.php instead of calling sitemap.php. Where am I going wrong? Thanks.
Moving the rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule sitemap.xml sitemap.php
to the top of the .htaccess file just after the RewriteEngine on directive seemed to solve my problem.

Access to my sub directories using htaccess

I'm using htaccess to rewrite my url first one is working fine now
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ /oneday/index.php?do=$1 [L,QSA]
to rewrite url but now I want to access my sub directories and my directories exists like this Oneday/files/pdf-generation/dock-receipt-PDF24032015.pdf and for this my code is
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\?*$ /oneday/files/pdf-generation/path$1
and my complete code of htaccess is
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ /oneday/index.php?do=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\?*$ /oneday/files/pdf-generation/path$1
but the second one is not working for me. How could I do this and Oneday is my project directory name.
Now first url create this link http://localhost/oneday/bookings and now I want to access my PDF files http://localhost/oneday/files/pdf-generation/dock-receipt-PDF03242015.pdf
You can target 2nd rule only for existing files:
RewriteEngine On
RewriteBase /Oneday/
RewriteCond %{DOCUMENT_ROOT}/Oneday/files/pdf-generation/path/$1 -f [NC]
RewriteRule ^(.+)$ files/pdf-generation/path/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?do=$1 [L,QSA]

htaccess rewrite condition not working

I am working on URL of my website. I have just rewrite the URL From
http://www.website.com/index.php?url=some-text
to
http://www.website.com/some-text
For this I'm using following code of .htaccess
Options +SymLinksIfOwnerMatch
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
Now, I want to add another variable page number in URL.
http://www.website.com/index.php?url=some-text&page=1
I want to rewrite it like
http://www.website.com/some-text/1/
AND
http://www.website.com/some-text/1
I have tried following code but some reason it is not working, it showing me server error.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/(.*)$ index.php?url=$1&page=$2 [L,QSA]
RewriteRule ^(.*)/(.*)/$ index.php?url=$1&page=$2 [L,QSA]
You don't need 2 new rules. Just one with optional / will be enough. Your complete code:
Options +SymLinksIfOwnerMatch -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?url=$1&page=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/?$ index.php?url=$1 [L,QSA]
Another problem in your new code is that RewriteCond are not getting applied for last RewriteRule since these are applicable to very next RewriteRule only.

Categories