I have new domain and for now I want to render all url to home page.
eg.
abc.com/abc
abc.com/abc/xyz
abc.com/abc/xyz/123
abc.com/abc/abc/xyz/123/so_on
also url will show only current home page ( index.html (or .php) ) instead of
"Not Found, The requested URL /index.php was not found on this server."
How can I do that using htaccess?
You can use a rewrite rule in .htaccess
RewriteEngine On
RewriteRule ^.*$ index.php [NC,L]
This will send all requests to index.php file(or you can change it to index.htm etc.)
also you can bypass static files like css/js and etc:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Related
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]
On this website and on wamp localhost
http://www.aproapetot.ro/page.php?categ_id=1&id=1
http://localhost/aproapetot-backup/page.php?categ_id=1&id=1
I tried to build the .htaccess, but without any success.
This is what I wrote for online website:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^page-([0-9]+).html$ page.php?categ_id=$1
RewriteRule ^page\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
and this for localhost
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /aproapetot-backup/
RewriteRule index.php index.html
RewriteRule ^page-([0-9]+).html$ page.php?categ_id=$1
RewriteRule ^page\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
Someone please give a little help.
It's a website with jokes so after .ro/page.php?categ_id=1&id=1 I have a category(1) and subcategory(1).
I want to have like this
.ro/jokes/doctors instead of how is now.
I'm not entirely sure what you want based upon the htaccess content, but what I do understand is that you want /jokes/doctors is rewritten to /pages.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !pages.php [NC]
RewriteRule ^(.*)$ /pages.php [L]
The above code will rewrite all requests to pages.php, as long as:
%{REQUEST_FILENAME} "!-f": The file itself does not exist on the server.
%{REQUEST_FILENAME} !pages.php: The request is not made to pages.php (meaning that it already has been rewritten)
Finally you can use PHP to obtain the parameters using:
/* Get all parameters from the URL */
$_GET['path'] = rawurldecode( $_SERVER['REQUEST_URI'] );
/* Remove double slashes and backslahses and convert all slashes and backslashes to '/' */
$_GET['path'] = preg_replace( array('#[/\\\\]+#', '/(\/\.)+(\/)/'), '/', $_GET['path']);
$_GET['path'][0] should contain "jokes"
$_GET['path'][0] should contain "doctors"
==edit==
Redirecting using htaccess (not the best method)
Redirect 301 /page.php?categ_id=6&id=0 /anecdotes
Redirect 301 /page.php?categ_id=1&id=1 /jokes/doctors
PHP (or other server side script). You can perform a check if the url is in fact having numbers (see $_SERVER['REQUEST_URI']) and ifso, add some header redirection to your page.
<?PHP
header('Location: www.aproapetot.ro/' . $cat . '/' . $subcat );
?>
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.
I want to redirect a particular set of Urls back to the index page of my site, but maintaining their url in the browser address bar. How would I go about to achieve this using mod_rewrite in a htaccess file?
The code currently used:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Custom rewrite below
RewriteRule ^references/(.*) / [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Please note that this is a WP install.
Put this in the htaccess file in your document root, preferably above rules you may already have:
RewriteEngine On
# for each of these "urls" do this
RewriteRule ^/?url_you_want_to_point_to_index / [L]
Assuming you have no query string parameters (the name/value pairs after a ?), that should be all you need.
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.