Block some internal urls using .htaccess in cakephp - regex

My site is running on cakephp 2.0 version , I want to block some of my site urls.
for example
www.exmaple.com/users/register
www.example.com/users/login
I tried to modify the .htaccess file of root , as well inside app folder but nothing work.
my code is
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
RewriteCond %{REQUEST_URI} ^/register
RewriteCond %{REQUEST_URI} ^/login
</IfModule>
Please help , how can I achieve it.
Thanks

You can use these rules:
<IfModule mod_rewrite.c>
RewriteEngine on
# block these URIs
RewriteRule (register|login) - [F,NC]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Related

.htaccess redirect .com.ar domain to .com

I have a domain mudomain.com.ar and want to redirect all incoming traffic to mudomain.com
I've tried this code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mudomain.com.ar$ [NC]
RewriteRule ^(.*)$ http://www.mudomain.com/$1 [R=301,L]
This rule redirects all traffic correctly. For example:
mudomain.com.ar/hello/ to mudomain.com/hello/
All traffic except traffic incoming to mudomain.com.ar/ar/
It seems like the .ar/ar/ in the domain is preventing the regex to work, but I can't understand why. Ideas?
Edit:
/ar/ contains the .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
And the webroot directory contains the .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
If you're using Apache 2.4 then add this line after RewriteEngine On line in your site root .htaccess:
RewriteOptions InheritDownBefore
Read more about RewriteOptions

htaccess regex wordpress not working

I have a wordpress site set up with some custom redirect rules set up. The weird thing is I am sure these all of these were working before but now some of them no longer function.
Here is the complete htaccess file:
RewriteRule ^properties/([a-zA-Z]+)/([a-zA-Z\+\'.]+) /properties/?prov=$1&city=$2&%{QUERY_STRING} [R,NC]
RewriteRule ^properties/([0-9]+) /properties/?id=$1 [R,NC]
RewriteRule ^([0-9][0-9][0-9][0-9][0-9])$ /properties/?id=$1 [R,NC]
RewriteRule ^expand.php?id=([0-9]+) /properties/?id=$1 [R,NC]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
right now the only rule that actually works (other than the directory change for wordpress itself) is
RewriteRule ^([0-9][0-9][0-9][0-9][0-9])$ /properties/?id=$1 [R,NC]
I've tried throwing in simple rules to test, like
RewriteRule ^/bob /contact [R,NC]
but that doesn't work either
* Edit the below issue was fixed and is definitely not related to the issue above (but I'll leave it here in case there was a comment that referenced it)*
Also, not sure if this gives any insight but on the page where the redirect actually works, my wordpress theme is broken, the wp_footer never fires and the rest of the page fails
Have it like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^bob/?$ /about [R,NC,L]
RewriteRule ^properties/([a-zA-Z]+)/([a-zA-Z+'.]+)/?$ /properties/?prov=$1&city=$2 [R,NC,QSA,L]
RewriteRule ^(?:properties/)?([0-9]+)/?$ /properties/?id=$1 [R,QSA,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
There are a couple of possible causes... You aren't enabling mod_rewrite until after your RewriteRules, the custom rules should be included inside their own <IfModule mod_rewrite.c> tag with RewriteEngine on preceding them, and you probably want to set RewriteBase to whatever the root of your site is (perhaps /wordpress subdirectory? you may want to include what you would like these rules to rewrite to and from.) You cannot match on a querystring within a RewriteRule either, you have to use a RewriteCond.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^properties/([a-zA-Z]+)/([a-zA-Z\+\'.]+) /properties/?prov=$1&city=$2&%{QUERY_STRING} [R,NC]
RewriteRule ^properties/([0-9]+) /properties/?id=$1 [R,NC]
RewriteRule ^([0-9]{5,5})$ /properties/?id=$1 [R,NC]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
Also updated ^([0-9][0-9][0-9][0-9][0-9])$ to the form ^([0-9]{5,5})$ which is a bit more readable.
Your example/test should look like the following - omit the / because it is set in the RewriteBase.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^bob /about [R,NC]
</IfModule>

How to put www in front of a wordpress site url in htaccess?

I have a wordpress site accessed like http://example.com/
but my client wants to have it accessed like http://www.example.com/
I am finding this code as a solution
# 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
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ www.domain.com/$1 [L,R=301]
But I am getting an error of redirect loop
Could you please advice me what am i doing wrong?
You're missing http:// from your www forcing rule. Also important is to have your www rule before other WP rules:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Also don't forget to change WP permalinks to have www in Site and Home URLs
You have an easy way to do this inside of wordpress:
Go to your wordpress dashboard and:
1) Select Settings
2) Select option General,
3) Add to your WordPress Address (URL) the www part
4) Add to your Site Address (URL) the www part
And done!

How to configure htaccess file for Cake 2.3.x on 1and1 shared hosting

Using the default cakephp htaccess file setup will not work on my domain when I want to install my Cakephp app in a subfolder, while everything works on localhost (xampp)
target => http://example.com/mycakeapp
Install needs 3 htaccess files:
root .htaccess
#.htaccess in root
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /mycakeapp
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
In app .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /mycakeap
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/ webroot/$1 [L]
</IfModule>
In webroot .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mycakeapp
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Following CakePHP's documentation, and Using these htaccess files, I get error500 results.
Using RewriteBase / instead of /mycakeapp will throw 404 error page.
PHP is in 5.4 version. How can I solve this?
/dirCakePhp
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /app/webroot/ [L]
RewriteRule (.*) /app/webroot/$1 [L]
</IfModule>
/direCakePhp/app
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /webroot/ [L]
RewriteRule (.*) /webroot/$1 [L]
</IfModule>
/direCakePhp/app/webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
</IfModule>
Juste add '/' after RewriteRule,
And change PHP version in 1and1 hosting panel to => 5.2
Add date_default_timezone_set('Europe/Paris'); in core.php
Setup your rules like this:
.htaccess in DOCUMENT_ROOT
RewriteEngine on
RewriteBase /
RewriteRule (.*) mycakeapp/$1 [L]
.htaccess in DOCUMENT_ROOT/mycakeapp
RewriteEngine on
RewriteBase /mycakeapp/
RewriteRule (.*) app/webroot/$1 [L]
.htaccess in DOCUMENT_ROOT/mycakeapp/app
RewriteEngine on
RewriteBase /mycakeapp/app/
RewriteRule (.*) webroot/$1 [L]
.htaccess in DOCUMENT_ROOT/mycakeapp/app/webroot
RewriteEngine On
RewriteBase /mycakeapp/app/webroot/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

HTAccess Redirect all Subpages

I'm trying to redirect all subpages of a page using .htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^/news-and-events(.*)$ /news/$1 [R=301,L,NC]
The above doesn't seem to be working, what's the easiest way to do this in as few lines as possible?
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
RewriteRule ^news-and-events(.*)$ /news/$1 [R=301,L,NC]
Remove leading slash:
RewriteRule ^news-and-events(.*)$ /news/$1 [R=301,L,NC]
.htaccess is per directory directive and Apache strips the current directory path from RewriteRule URI pattern.