How to remove this part from URL using htaccess? - .htaccess

I have this URL:
http://www.register.abc.com/myapp/administrator/registration
Which is :
http://www.register.abc.com is my domain
myapp is my aplication folder in server
administrator/registration is my controller and function
What I'd like to do is to remove this part /myapp/administrator/registration from my URL. In default, when user only enter the http://www.register.abc.com/ it will be redirected to my home page. I'd like to set it so the user directly enter registration page not the home page. I have little to no knwledge about .htaccess. Any help is greatly appreciated.
Note: I am using wiredesignz codeigniter modular extensions hmvc
Edit:
my current .htaccess is like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /myapp
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

In your site root .htaccess (a level above myapp/ you may try this .htaccess code:
RewriteEngine On
RewriteRule ^$ myapp/administrator/registration [L,R=302]
If you want an internal rewrite (without changing URL) then try:
RewriteRule ^$ myapp/administrator/registration [L]

Related

Remove subfolder with htaccess

This is the architecture of my website :
/
app/
index.php
...
libs/
lib1/
file.php
lib2/
...
I need to access index.php by this url : domain.com/index.php
I tried this :
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)app
RewriteRule ^(.*)$ app/$1 [L]
It works, but inside my index.php, I call for example :
include('../libs/lib1/file.php');
It's doesn't work because this path refer to root now...
And I can't access to domain.com/libs anymore, because it's looking for domain.com/app/libs.
How can I do ?
The include() shouldn't care what the path the browser sees. That should be based on the local filesystem on the server. But your rules are affecting direct access to the libs, so try adding a few more conditions:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^app/
RewriteRule ^(.+)$ app/$1 [L]
RewriteRule ^$ app/index.php [L]
This makes it so requests for existing files or content won't get routed through the app folder.

Add get variables to url throung htaccess file

I want to add one get parameter to the every url on my wprdpress website except the index page.
For example,
Consider website name to be www.example.com
If www.example.com is hit than nothing should happen
But if I hit www.example.com/events than a get parameter viz. "home" be appended to it. Final URL should be as follows:
www.example.com/events/?home
I want to use this parameter for further processing.
my current .htaccess file contains following
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{QUERY_STRING} !lp-variation-id
RewriteRule ^go/([^/]*)? /wp-content/plugins/landing-pages/modules/module.redirect-ab-testing.php?permalink_name=$1 [QSA,L]
RewriteRule ^landing-page=([^/]*)? /wp-content/plugins/landing-pages/modules/module.redirect-ab-testing.php?permalink_name=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
and i m working on wordpress project.
Try this:
RewriteCond !^/$
RewriteRule ^/(.*)$ /$1?home
Depending on your hosting environment the URL may or may not start with a slash, so you might have to remove it from the RewriteRule.

Redirect url with .htaccess

I m sure that many people will say that this is duplicated but I try everything from other "Question"`s and nothings work for me.
The problem is that I move my project to the web server.
In this server I have folder "public_html" where I but my project Symfony.
Now to enter on my project I must write the following url: www.mydomain.com/Symfony/web/*
But I want to write a Rewrite Rule which will redirect from www.mydomain.com/Symfony/web/* to
www.mydomain.com/home/*.
To do this I try on 2 different ways with many combination of ReWrite rule.
In my public_html I create a .htaccess folder
I edit the .htaccess in Symfony/web folder
I add the following rule in both file but without success
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^Symfony/web/(.*)$ www.mydomain.com/home/$1 [L,R=301]
Unfortunately without success. What I`m doing wrong?
My htaccess file look like
And all the time Error 404 Object not found
Symfony/web/.htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteRule ^home/(.*)$ $1 [L,NC]
</IfModule>
It`s redirecting me but I receive again Object not found :(
I delete the .htaccess in public_html folder which is the root one for my server
public_html\.htaccess
RewriteEngine On
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
1: Place this code in /Symfony/web/.htaccess:
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [L]
2: Place this code in /public_html/.htaccess:
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
I'm going to go out on a limb and say that your rule is backwards. I think you want your URL to be www.mydomain.com/home/* in the browser... In which case the rule would be reversed. Also, your .htaccess should be in the root and you don't need to include the domain in the rewrite rule because you set a rewrite base.
RewriteRule ^home/(.*)$ Symfony/web/$1 [L,R=301]

Htaccess redirect with cakePHP

I have a cakePHP app working at http://domain1.com/domain2, and want to point http://domain2.com/ to this application.
I have done this change the document root of domain2 to public_html/domain2, but, when I go to: domain2.com all css, javascript and images are not loaded, with a message saying controller not found.
What I can do?
All domains have a folder with their domains without the TLD at domain1.com, I think if I create a htaccess and get the domain without TLD, and finally change rewriteBase, will work as expected, but don't know how to do this.
Current htaccess of domain2:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
You can try adding an htaccess file in domain2's document root with the following rules:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} \.(css|js|png|jpe?g|gif|bmp|ico)$ [NC]
RewriteRule ^/?domain2/(.*) /$1 [L,PT]
This should remove the domain2 part of the links.

Redirect subdir with .htaccess

My first question here! :) Hello!
I have some trouble with .htaccess.
http://www.domain.com/subdir/?parameter=example works.
http://www.domain.com/subdir/example doesn't work.
When i try this:
RewriteBase /subdir
RewriteRule ^index.php - [L]
RewriteRule ^([^/]+)/?$ index.php?i=$1 [R,L]
i get an 404.shtml error like http:// www.domain.com/subdir/index.php?i=404.shtml
Also the wp-admin(http:// www.domain.com/wp-admin/) redirects to the subdir with 404.shtml. How do i get the url like http:// www.domain.com/subdir/example/
Can anyone help me?? Thnx in advanced!
Assuming this is a WordPress installation (based on the mention of 'wp-admin'), you want the following
Just use the WordPress standard, put this .htaccess into the root folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdir/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdir/index.php [L]
</IfModule>
Go to Settings and change Site address (URL) under General Settings to http://www.domain.com/subdir/
Put the following index.php into the root folder
<?php
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require('./subdir/wp-blog-header.php');
?>
Go to Settings > Permalinks and change the permalink structure to whatever you need
p.s. to access wp-admin you need to navigate to http://www.domain.com/subdir/wp-admin/
more info here: http://codex.wordpress.org/Moving_WordPress#Giving_WordPress_its_Own_Directory_While_Leaving_the_WordPress_Index_File_in_the_Root_Directory

Resources