I have the following .htaccess rules:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^sitemap_(.*)\.xml$ /xml/sitemap/$1 #[L]
RewriteRule ^.*$ /index.php [NC,L]
Unfortunately I can not use internal Zend Framework routing for processing sitemaps, but the rules above do not work.
Sitemap URLs look like:
/sitemap_index.xml
/sitemap_pages.xml
/sitemap_news.xml
Required rewrite works fine in cases I set it R=301 redirect or comment out the last rule. Both of these are not options. Can anyone help please?
Can't say about .htaccess. May be easier to do by zend router. Put this in the bootstrap:
public function _initRouter() {
$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$route = new Zend_Controller_Router_Route_Regex(
'sitemap_(.*)\.xml',
array(
'controller' => 'xml',
'action' => 'sitemap'
),
array(
1 => 'sitemap'
)
);
$router->addRoute('sitemap', $route);
}
Related
I have sample website name is example.com/customer/?loc=dashboard, this website is used PHP coding. I need to change last name ?loc=dashboard to dashboard. That means I want the result website name is mydomain.com/customer/dashboard
I have added a file called .htaccess in my root folder, and add something like this, but it cannot work:
ReWriteEngine On
RewriteRule ^/dashboard /?loc=dashboard [L]
I have refer this website https://mediatemple.net/community/products/dv/204643270/.htaccess-rewrite-rules to do. But cannot work. Hope someone can guide me on how to solve this problem. Thanks.
Updated - 1
Using #RavinderSingh13 method result:
Before ?loc=dashboard result:
Updated 12/11/2021 09:19:00
Rewrite rules
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com\.my [OR,NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com.my/$1 [R,L]
RewriteCond %{HTTP_HOST} ^example\.com\.my [OR,NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.com.my/$1 [R,L]
##External redirect to /customer/dashboard url rules here.
RewriteCond %{THE_REQUEST} \s/customer/?\?loc=(\S+)\s [NC]
RewriteRule ^ /customer/%1? [R=301,L]
##Internal rewrite rules to get it served by index.php file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^customer/(.*)/?$ index.php?parameter=$1 [QSA,NC,L]
Update - 2
everyoneknows.come.my/.htaccess
everyoneknows.come.my/index.php
everyoneknows.come.my/customer
everyoneknows.come.my/customer/index.php
everyoneknows.come.my/customer/account/dashboard.php
So that, in my php code, I use ?loc= replace account, then become everyoneknows.come.my/customer/?loc=dashboard
Update -3
I am using this method to get ?loc:
if (isset($_GET['loc'])) {
if (file_exists('account/' . $_GET['loc'] . '.php')) {
// if ($module_user_permission['view'] == 1) {
include_once 'account/' . $_GET['loc'] . '.php';
// } else {
// if ($_GET['loc'] != 'home') {
// include_once 'app/access_denied.php';
// } else {
// include_once 'account/dashboard.php';
// }
// }
} else {
include_once 'account/dashboard.php';
}
} else {
include_once 'account/dashboard' . (isset($_GET['system']) ? "_" . $_GET['system'] : "") . '.php';
}
With your shown attempts, samples; please try following htaccess rules file. Please make sure to clear your browser cache before testing your URLs.
Make sure your htaccess rules file is present alongside with customer folder(not inside it). In 2nd rewrite rule I have added parameter to get it pass to index.php file you can set it as per your requirement.
RewriteEngine ON
##Applying www by external redirect rules here...
RewriteCond %{HTTP_HOST} ^example\.com\.my [NC]
RewriteCond HTTPS off
RewriteRule ^(.*)/?$ https://www.example.com.my/$1 [R,L]
##External redirect to /customer/dashboard url rules here.
RewriteCond %{THE_REQUEST} \s/customer/?\?loc=(\S+)\s [NC]
RewriteRule ^ /customer/%1? [R=301,L]
##Internal rewrite rules to get it served by dashboard.php file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^customer/(.*)/?$ customer/account/dashboard.php?parameter=$1 [QSA,NC,L]
If I enter the URL:
http://localhost/third/web/calculator
it just works fine. I now want to remove the web portion from the URL. I currently do not have .htaccess. And if I enter http://localhost/third/calculator it shows object not found.
I added this .htaccess in the root folder of the project:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/third/(assets|css)
RewriteRule ^assets/(.*)$ web/assets/$1 [L]
RewriteRule ^css/(.*)$ web/css/$1 [L]
RewriteCond %{REQUEST_URI} !^/third/web/(assets|css)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ web/index.php
Now if I enter http://localhost/third/calculator it shows the congratulations page of yii2, instead of the calculator page. If click in any other tabs like login with link <span class="glyphicon glyphicon-log-in"></span> Login the url shows the web still.
First you change config->web.php
'components' => [
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
]
Add .htaccess file in your project root directory
# prevent directory listings
Options -Indexes
IndexIgnore */*
# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteRule ^(/.+)?$ web/$1 [L,PT]
RewriteRule ^(.+)?$ web/$1
Also you have to add .htaccess file in your_project->web directory
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
I have a problem with hiding part of url in Kohana 3.
There are controlers stored in admin subfolder.
These controlers power admin panel of site.
So when I type :
http://mysite.xyz/admin
it works ok. I need only admin panel of that kohana project, and I decided to create subdomain admin.
So now when I type:
http://admin.mysite.xyz/admin
it works ok.
But I want to hide that admin part of url and when I will type:
http://admin.mysite.xyz
I will not load kohana site, but admin panel.
Here is my .htaccess:
RewriteEngine On
RewriteBase /
###### Add trailing slash (optional) ######
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [L,R=301,NE]
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*)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]
RewriteCond %{HTTP_HOST} ^(www.)?admin.schoener-tauchen.pl$
RewriteRule ^(/)?$ admin [L]
RewriteRule ^admin/(.+)$ $1 [L,NC,R]
It doesn't work. It gives 404 error.
Can someone help, please?
PS. Changing Kohana routing is unfortunately very complicated in this case. Htaccess changes seems to be easier.
EDIT
bootstrap.php route:
Route::set('admin', 'admin(/<controller>(,<action>(,<id>)(,<id2>)(,<id3>)))')
->defaults(array(
'directory' => 'admin',
'controller' => 'home',
'action' => 'index',
));
Route::set('default', '(<controller>(,<action>(,<id>)))', array('controller'=>'\w+','controller'=>'\w+', 'action'=>'\w+', 'param' => '.+'))
->defaults(array(
'directory' => 'admin',
'controller' => 'home',
'action' => 'index',
));
Use bootstrap.php
$is_admin = preg_match('/^admin\.schoener-tauchen\.pl$/', $_SERVER['HTTP_HOST']);
Route::set('default', '(<action>(/<id>))')
->defaults(array(
'controller' => $is_admin ? 'admin' : 'index',
'action' => 'index',
));
And remove from .htaccess
RewriteCond %{HTTP_HOST} ^(www.)?admin.schoener-tauchen.pl$
RewriteRule ^(/)?$ admin [L]
RewriteRule ^admin/(.+)$ $1 [L,NC,R]
I will suggest this solution, comment out both routes in bootstrap and replace them with this.
Kohana::init ( array (
'base_url' => '/'
));
Route::set('default', '(<controller>(,<action>(,<id>)(,<id2>)(,<id3>)))')
->defaults(array(
'directory' => 'admin',
'controller' => 'home',
'action' => 'index',
));
Here is Kohana official route guide
Ok. I solved it by the hack in .htaccess:
RewriteRule ^admin/(.+)$ $1 [L,NC,R]
In view's files and controllers there are links, URLs which contain that admin. Htaccess force it to skip that admin part.
i need redirect domain in .htaccess in root on server.
My .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/yii/projectName/
RewriteRule ^(.*)$ /yii/projectName/$1 [L]
Home page application works, but url manager doesn't work, it always redirects to home page.
My urlManager:
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
...
),
Thank you for your help
Try this:
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
I found this alternative solution a year ago here: http://www.yiiframework.com/wiki/214/url-hide-index-php/
EDIT:
URL manager settings seems to be OK, but be sure to add these rules AFTER your custom url rules:
'rules'=>array(
// ... add you custom url rules here, if there are any
// Home page
'/' => 'info/index', // edit this to your home page controller/action
// Default patterns for any other controller/actions.
// These are checked last, if there were no applicable custom rules for a specific URL
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>/*' => '<controller>/<action>'
),
Hi everyone I am having a problem in setting up the .htaccess URL fix for CodeIgniter Framework.
I have a site launched in a folder named "sites".
=> THE PROBLEM:
**This URL works perfectly:
http://127.0.0.1/sites/home/index/test
I want to get rid of /index/ from the URL
The destination URL should be like this:
http://127.0.0.1/sites/home/test
How can i acheive this URL?
Additional Info:
I have URL helper in autoload done which works great and here is the code in My Controller
class Home extends CI_Controller {
public function index($var='')
{
echo $var; //outputs -> test
}
}
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteBase /sites
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
RewriteRule ^(.*)$ index.php/$1 [L]
To do that, you want to add a route in config/routes.php:
route['home/(:any)'] = "home/index";