Rewrite rules to subfolder - .htaccess

I have my website on a subfolder
/application
/application/php (all php files)
/application/view (my templates files)
/application/admin (my admin)
on my .htaccess i have this condiction to the main files
RewriteRule ^(.+)\/?([0-9]*)\/?$ application/php/index.php
my website work perfect
www.mysite.com/
now i want to rewrite rules for the admin folder
www.mysite.com/admin read /application/admin/
i tried something like this but dont work
RewriteRule admin/^(.+)\/?([0-9]*)\/?$ application/admin/index.php
My FUll .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !^(.+)\.(css|js|xml|swf|flv|pdf)$
RewriteCond %{REQUEST_FILENAME} !^(.+)\.(jpg|jpeg|png|gif)$
RewriteCond %{REQUEST_FILENAME} !^(.+)\.(ttf|otf|eot|woff|svg)$
RewriteCond %{REQUEST_FILENAME} !cron.php
RewriteCond %{REQUEST_FILENAME} !/cache
RewriteCond %{REQUEST_FILENAME} !favicon.ico
RewriteCond %{REQUEST_FILENAME} !robots.txt
RewriteCond %{REQUEST_FILENAME} !ajax.php
RewriteCond %{REQUEST_FILENAME} !sitemap.xml
RewriteCond %{REQUEST_FILENAME} !/template/(.*)\.html
RewriteCond %{REQUEST_FILENAME} !/application/inc/OAuth(.*)\.php
RewriteRule ^(.+)\/?([0-9]*)\/?$ application/php/index.php
#RewriteRule admin/^(.+)\/?([0-9]*)\/?$ application/admin/index.php (not work)
<IfModule mod_expires.c>
<FilesMatch "\.(ico|gif|jpg|jpeg|png|js|css)$">
ExpiresActive On
ExpiresDefault "access plus 30 days"
FileETag None
</FilesMatch>
<FilesMatch "\.(xml|php)$">
ExpiresActive On
ExpiresDefault "access plus 5 minutes"
FileETag None
</FilesMatch>
</IfModule>

Have it this way:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin/assets(?:/.*)?$ application/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin(?:/.*)?$ application/admin/index.php [L]
RewriteCond %{REQUEST_FILENAME} !^(.+)\.(css|js|xml|swf|flv|pdf)$
RewriteCond %{REQUEST_FILENAME} !^(.+)\.(jpg|jpeg|png|gif)$
RewriteCond %{REQUEST_FILENAME} !^(.+)\.(ttf|otf|eot|woff|svg)$
RewriteCond %{REQUEST_FILENAME} !cron.php
RewriteCond %{REQUEST_FILENAME} !/cache
RewriteCond %{REQUEST_FILENAME} !favicon.ico
RewriteCond %{REQUEST_FILENAME} !robots.txt
RewriteCond %{REQUEST_FILENAME} !ajax.php
RewriteCond %{REQUEST_FILENAME} !sitemap.xml
RewriteCond %{REQUEST_FILENAME} !/template/(.*)\.html
RewriteCond %{REQUEST_FILENAME} !/application/inc/OAuth(.*)\.php
RewriteRule ^(.+)/?([0-9]*)/?$ application/php/index.php [L]

Related

Rewriting the URL using .htaccess blocking the adsense ads

I am rewriting the URL subdomain.domain.com/result.php?domain=example.com using .htaccess
When I hit the above URL google AdSense ads show on the web page but when I rewrite the URL to subdomain.domain.com/example.com google Adsense ads stops showing on the page. My URL and subdomain are verified on AdSense. I am not getting what is happening here. Why ads are being blocked. Why it is not showing. Below is the .htaccess code I am using:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/([a-zA-Z0-9]+)/ pages.php?page=$1 [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^top/([a-zA-Z0-9]+)/ top.php?p=$1 [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ result.php?domain=$1 [L]
</IfModule>
Please let me know what can I update in the code.

Htaccess conflict rules

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>

Frog CMS htaccess diagnosis

I have a issue with Frog CMS, its the first time I use this CMS, is a client that uses this.
Scenario: I modified 1 redirection using a plugin called "Redirector" that destroyed the whole site!
Luckly, I found an htaccess from some months ago, that allows the site to work, but the redirections none of them works, the site works, but not the redirections, the main url rewriting for the site seems to be Ok, but the 301 redirects I need, dont work.
I cant figure out why this is happening, why this redirections dont work correctly, they dont conflict, but they dont do nothing! Can you advice on this ? Im looking forward uderstanding more about url rewritting and htaccess.
I cant use the plugin to generate redirections, because it destroyed the whole site. If there is a way to "reset" the url rewritting in this CMS it would be good, but I dont have cooperation form the developers of the site...
I appreciate any help to understand better what is wrong , why all the
RewriteRule ^site/services/immigration/ /services/immigration.html [L,R=301]
dont work!
### CMS-Generated Update August 1, 2013, 1:45 pm ###
#
# Setting Frog requirements
#
AddType text/x-component .htc
AddType video/ogg .ogm
AddType video/ogg .ogv
AddType video/ogg .ogg
AddType video/webm .webm
AddType video/mp4 .mp4
AddType video/x-m4v .m4v
AddType audio/webm .weba
AddDefaultCharset UTF-8
Options -Indexes -MultiViews +FollowSymLinks
DirectoryIndex index.html index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !.local$ [NC]
RewriteCond %{HTTP_HOST} !.local$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^install/index.html$ install/index.php?rewrite=1 [L,QSA]
RewriteRule ^install/index.php$ install/index.php?rewrite=1 [L,QSA]
RewriteRule ^install/$ install/index.php?rewrite=1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^admin(.*)$ admin/index.php?$1 [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
RewriteRule ^$ /cache/index.html [L,QSA]
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{DOCUMENT_ROOT}/cache/%{REQUEST_URI} -f
RewriteRule ^(.*)$ /cache/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^download/(.*)$ /downloads.php?THISPAGE=download.html&media=pdf&filename=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^private/(.*)$ /private.html?THISPAGE=private.html&userfile=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^mobile/search/(.*)$ mobile.html?THISPAGE=search.html&media=mobile&search=$1 [L,QSA]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-l
#RewriteRule ^mobile/(.*)/process.html$ mobile.html?THISPAGE=$1&media=mobile&return=process [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^mobile/(.*)/success.html$ mobile.html?THISPAGE=$1&media=mobile&return=success [L,QSA]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^standard/search/(.*)$ standard.html?THISPAGE=search.html&media=standard&search=$1 [L,QSA]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-l
#RewriteRule ^standard/(.*)/process.html$ standard.html?THISPAGE=$1&media=standard&return=process [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^standard/(.*)/success.html$ standard.html?THISPAGE=$1&media=standard&return=success [L,QSA]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-l
#RewriteRule ^(.*)/process.html$ contact.html?THISPAGE=$1&return=process [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/success.html$ contact.html?THISPAGE=$1&return=success [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^search/(.*)$ index.php?THISPAGE=search.html&search=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^proposal.html$ index.php?THISPAGE=$1&media=proposal [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^contrast/search/(.*)$ contrast.html?THISPAGE=search.html&search=$1&media=contrast [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^print/search/(.*)$ print.html?THISPAGE=search.html&search=$1&media=print [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^mobile/(.*)$ mobile.html?THISPAGE=$1&media=mobile [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^standard/(.*)$ standard.html?THISPAGE=$1&media=standard [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^print/(.*)$ print.html?THISPAGE=$1&media=print [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^pdf/(.*)$ pdf.html?THISPAGE=$1&media=pdf [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^proposal/(.*)$ proposal.html?THISPAGE=$1&media=proposal [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^flash/(.*)$ flash.html?THISPAGE=$1&media=flash [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^contrast/(.*)$ contrast.html?THISPAGE=$1&media=contrast [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?THISPAGE=$1 [L,QSA]
RewriteRule ^/site/aboutus/(.*)$ /$1 [L,R=301]
RewriteRule ^site/aboutus/ / [L,R=301]
RewriteRule ^pages/about_us.htm /about.html [L,R=301]
RewriteRule ^site/contact/ /contact.html [L,R=301]
RewriteRule ^site/library/ /resources.html [L,R=301]
RewriteRule ^site/services/ /services.html [L,R=301]
RewriteRule ^site/services/alternative_dispute_resolution/ /services/alternative-dispute-resolution.html [L,R=301]
RewriteRule ^site/services/business_visas/ /services/business-visas.html [L,R=301]
RewriteRule ^site/services/civil_comm_litigation/ /services/civil-commercial-litigation-copy.html [L,R=301]
RewriteRule ^site/services/clinical_negligence/ /services/clinical-negligence.html [L,R=301]
RewriteRule ^site/services/conveyancing/commercial/ /services/commercial-conveyancing.html [L,R=301]
RewriteRule ^site/services/company_law/ /services/company-law.html [L,R=301]
RewriteRule ^site/services/criminal_law/ /services/criminal-law.html [L,R=301]
RewriteRule ^site/services/divorce_matrimonial/ /services/divorce-matrimonial.html [L,R=301]
RewriteRule ^site/services/employment_law/ /services/employment-law.html [L,R=301]
RewriteRule ^site/services/human_rights/ /services/human-rights-issues.html [L,R=301]
RewriteRule ^site/services/immigration/ /services/immigration.html [L,R=301]
RewriteRule ^site/services/leases_tenancy/ /services/leases-tenancy-agreements.html [L,R=301]
RewriteRule ^site/services/injury_medical_negligence/ /services/personal-injury-medical-negligence.html [L,R=301]
RewriteRule ^site/services/pro_bono/ /services/pro-bono.html [L,R=301]
RewriteRule ^site/services/conveyancing/ /services/residential-conveyancing.html [L,R=301]
RewriteRule ^site/services/conveyancing/residential/ /services/residential-conveyancing.html [L,R=301]
RewriteRule ^site/services/wills_trusts_probates/ /services/wills-trusts-probates.html [L,R=301]
RewriteRule ^site/people/ /team.html [L,R=301]
</IfModule>
It's because you have this rule before all of your other services redirect rules:
RewriteRule ^site/services/ /services.html [L,R=301]
This is saying, "anything that starts with /site/services/ gets redirected to /services.html". So, when you have a rule like:
RewriteRule ^site/services/company_law/ /services/company-law.html [L,R=301]
after it, the second rule will never get executed, since the second rule matches /site/services/company_law, which starts with /site/services/, thus matching the first rule. You need to re-order all of your rules so that the more general rule is at the end. Just put the
RewriteRule ^site/services/ /services.html [L,R=301]
rule at the very bottom.

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>

.htaccess: Transfer name to index.php if not directory public

I have this piece of code:
Options FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
I don't know how to allow only directory with name "public" which is inside folder where is .htaccess, other names than this dir should be transfered to index.php. How could I do that?
Add another RewriteCond to exclude public directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} ^/public(/.*)?$
RewriteRule ^(.*)$ index.php?url=$1 [L]
Now, the redirection would only work for /public directories only. If you want the url to just have the rest of the path that's below public like url=subfolder/page.php for /public/subfolder/page.php use
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^public/?(.*)$ index.php?url=$1 [L]
Change your code with this:
Options +FollowSymLinks -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (?!^public(/.*|)$)^(.*)$ index.php?url=$1 [L,NC,R=302]
ErrorDocument 404 /index.php
</IfModule>

Resources