apache don't rewrite index.php and others - apache2

I have problems with my rewrite rules, I want that http://example.com/b/abc calls banner.php?b=abc, that works. But when I type http://example.com/index.php?mode=mybanners it will call banner.php?b=index.php?mode=mybanners (or something like this). My .htacces file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule b/?(.+)$ ./banner.php?b=$1
RewriteRule i/?(.+)$ ./banner.php?bi=$1
</IfModule>
Some ideas to let /index.php interact normal?

Try below rules :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule b/?(.+)$ ./banner.php?b=$1
</IfModule>

Related

Setup .htaccess to read static folder from a main subfolder instead the public_html

I decided to change my react-app files to be at the subfolder public_html/main/ --for git automation reasons--, then I also made some changes in my .htaccess file so it can read the main folder.
Now, reading the main/index.html is working fine, although the .htaccess is not detecting static/ inside main, instead is looking for it in public_html/ (I know it because when I put static there it worked). And I need to change in some way this dot file to read static in the subfolder.
I have the next folder tree structure at my server:
public_html/
.htaccess
main/
index.html
static/
css/
js/
media/
While .htaccess looks like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
RewriteCond %{HTTP_HOST} ^(www.)?udecursos.study$
RewriteCond %{REQUEST_URI} !^/main/
RewriteRule ^(.*)$ /main/$1
RewriteCond %{HTTP_HOST} ^(www.)?udecursos.study$
</IfModule>
I managed to solve it, when I knew that you can have a .htaccess file in both folders, the root and the sub one. When the dot file in the subfolder will override the others .htaccess.
So I configured the root (public_html/) .htaccess like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?udecursos.study$
RewriteCond %{REQUEST_URI} !^/main/
RewriteRule ^(.*)$ /main/$1
RewriteCond %{HTTP_HOST} ^(www.)?udecursos.study$
While in the subfolder with location public_html/main/ the .htaccess ended
up like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
Actually working and reading the needed files.

Wordpress Apache RewriteRule

I would like to redirect the Facebook crawlers to a static page, since my website is in AngularJS and I need to work with the og:meta. I'm using Wordpress as back-end, so at the moement this is my .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I tryed to add these two lines:
RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/[0-9]|Twitterbot|Pinterest|Google.*snippet)
RewriteRule tracks/(\d*)$ http://<path>/static.php [P]
But this is not working. If I try to scrape a page with the facebook tool (https://developers.facebook.com/tools/debug/) I'm not redirect to the static page.
Keep in mind that in wordpress my permalinks are build in this way: http://<fqdn>/%category%/%postname%/ and tracks/ is one of my category.
The solution was to exclude the facebook crawler from the default 302 of wordpress.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/1.1
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} facebookexternalhit/1.1
RewriteRule (.*) http://<dn>/static.php [L]
</IfModule>

Ignore folders in htaccess

I'm making a webapp using AngularJS. For routing, I used a htaccess rewrite rule to allow direct access to routing pages (for example going directly to /settings). However there is one folder I would like to exclude from this rule, so I can check if a file exists (now every URL returns 200). I've tried every combination of rewrite conditions and rules I could find, but no luck.
So far this is my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
#Options FollowSymLinks
RewriteBase /
RewriteCond %{REQUEST_URI} !(orders)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]
</IfModule>
ErrorDocument 404 /404.php
I would appreciate any help
EDIT:
I would like to exclude all files and folders under orders
Try
RewriteCond %{REQUEST_URI} !^/orders [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]
%{REQUEST_URI} always starts with a / and because you aren't specifying something like .* at the beginning of the regex, you have to have the slash. I also added the [NC] flag so that a url like "/ORDerS" would be skipped as well.

having issues with htaccess in codeigniter Angularjs

My front end is in angular. I am using HTML5 mode routing in angular. I have configured my htaccess file for redirecting any URL to index.php, But it seems that it is not working.
Below is my htaccess code :
Options +FollowSymLinks
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.php/#/$1 [L]
</ifModule>
Please help.
Change this line :
RewriteRule (.*) index.php/#/$1 [L]
By this :
RewriteRule ^(.*)$ /index.php?/#/$1 [L]

Installing/Setting cakePHP on Server

I'm trying to setup my cakephp work on server
Purchased godaddy shared server
when i go to my site http://xyz.com/cake/
I'm getting 404 error
The requested URL /xyz/cake/app/webroot/ was not found on this server.
anyhelp plz ??
Thanks,
Satish
You need to set the correct RewriteBase in your .htaccess if you're going to run Cake inside a subdirectory.
Both /xyz/cake/.htaccess and /xyz/cake/webroot/.htaccess (assuming /xyz/cake is the path to Cake and your app dir) need to be updated.
/xyz/cake/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /xyz/cake/
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/xyz/cake/webroot/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /xyz/cake/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

Resources