Htaccess conflict rules - .htaccess

My Htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^home/?$ index.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?([^/]+)/?$ departure.php?PDt2=$1 [QSA,NC,L]
RewriteRule ^(.+)/(.+)/(.+)$ service.php?DPt=$1&CTg=$2&NLs=$3 [QSA,NC,L]
</IfModule>
The rule of service.php url does not work.
Why the error occur?

Try changing your rules around and adding conditions to both rules. See if this helps.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^home/?$ index.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ service.php?DPt=$1&CTg=$2&NLs=$3 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?([^/]+)/?$ departure.php?PDt2=$1 [QSA,NC,L]
</IfModule>

Related

htaccess multiple rules - paths break

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^user/([0-9]+)/?$ index.php?a=user&id=$1 [QSA,L]
RewriteRule ^img/([0-9]+)/?$ index.php?a=img&id=$1 [QSA,L]
RewriteRule ^(.*)$ index.php?a=$1 [QSA,L]
Options -Indexes
The htaccess rules are breaking the paths of the files.
Someone have an idea?
This should work :
Options -Indexes
RewriteEngine On
RewriteRule ^user/([0-9]+)/?$ index.php?a=user&id=$1 [QSA,L]
RewriteRule ^img/([0-9]+)/?$ index.php?a=img&id=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?a=$1 [QSA,L]

Url Rewrite - Add Query String Too 999

DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
RewriteRule ^tags tags.php [L,NC]
</IfModule>
i want to add new page .but write page not found. why? please help me.
RewriteRule ^tags tags.php [L,NC] // i want this www.example.com/tags open tags.php ?
You need to reorder your htaccess rules like this :
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteRule ^tags/?$ tags.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>
The problem is that, your rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
Rewrites any request (not a true file/dir) to index.php. since /tags is not an existent file on your directory, so a request for http://example.com/tags was being rewritten to /index.php and the last rule(s) never executed.

Codeigniter: specified word after url redirect to subfolfer

I have Codeigniter 3 project in root directory. I need to use it with kohana other project which is in subfolder (admin).
I need to make redirect, when I will type mysite.xyz/admin that will redirect me to subfolder admin, where are kohana files: index.php etc.
Now CodeIgniter think that admin is a controller.
My .htacces file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projekty/folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule admin/^(.*)$ /admin/ [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Have any ideas, how to solve that? I was trying to find some solutions, but no success.
Here is Kohana .htaccess:
RewriteEngine On
RewriteBase /projekty/folder/admin/
###### Add trailing slash (optional) ######
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [L,R=301,NE]
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*)home/u343855449/public_html/projekty/folder/admin/index.php/(.*)$ /$1$2 [R=301,L,NE]
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|media)
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L,QSA]
your admin rule is in the wrong place. It needs to come before the CI rules. Put it below the rewritebase. Try these rules.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projekty/folder/
RewriteRule ^admin/(.*)$ /admin/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Actually you really don't need the admin rule. Just tell it to ignore admin in the CI rules as below.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projekty/folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/admin [NC]
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

How to change URL structure with htaccess?

I have downloaded and installed http://www.question2answer.org/ on my website on http://www.yourstartups.com/discussion/ (discussion sub-directory)
Current url structure is like: example.com/index.php?qa=123&qa_1=why-do-birds-sing
I want to change to /123/why-do-birds-sing
(why-do-birds-sing is example query)
Following is my htaccess:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>
Can anyone help me?
You need a new rule to rewrite your pretty URL.
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?qa=$1&qa_1=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0 [L,QSA]
</IfModule>

Rewrite rule to end all URL's with .html including /index.html in the root and other directories

My question is, How can I rewrite all of my URL's in a way that will add .html to the end of every URL?
here is my .htaccess rule that I have
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
</IfModule>
I have tried adding .html to index.php/$1.html but this is throwing 404 all over the place.
Please help
You can use:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+?)/?$ $1.html [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)\.html$ index.php/$1 [L,NC]
</IfModule>

Resources