I have installed Yii2 advanced app and what i am trying to do now is to redirect this url htpp://site/admin to the backend ( admin ) side. What i tried so far is:
AddDefaultCharset utf-8
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# Make the backend accessible via url: http://site/admin
RewriteRule ^admin$ $admin.php [L]
# 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
RewriteRule ^static - [L]
I am not familiar whit .htaccess and i am not pretty sure what is the right way. This code is what i found after googling. The .htaccess file is in the app/backend/web/.htaccess. Can you point me the right way? Thank you in advance!
easy :
RewriteEngine On
# End the processing, if a rewrite already occurred
RewriteRule ^(frontend|backend)/web/ - [L]
# Handle the case of backend, skip ([S=1]) the following rule, if current matched
RewriteRule ^admin(/(.*))?$ backend/web/$2 [S=1]
# handle the case of frontend
RewriteRule .* frontend/web/$0
# Uncomment the following, if you want speaking URL
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([^/]+/web)/.*$ $1/index.php
Related
I'm relatively new to Codeigniter and MVC. But, have successfully made two apps 'Locally'. While exploring, I found a way to remove 'Index.php' from the URL and also about custom routes. The .htaccess file that i have works like charm locally, but when trying to host it; there is a issue 505 internal server issue
Here is the first .htaccess code that i have (works locally) :-
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
When i use the code above there is an error. And, the app works only when .htaccess is removed. (I then have to use the inconvenient long URLs)
After a brief research and using different .htaccess without success, i asked one of my friends who has a Hosted CI app successfully running. He sends me a file which leads me the landing page without any problem; but, cant call any functions with/without using routing .i.e. If i use the custom routed URl (www.mySite.com/contact) then also it leads me to the landing page, the same with actual URL scheme (www.mySite.com/welcome/contact_page)
The new code here:-
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Using this code shows me the landing page but i cannot navigate any further from there. When i try to call a function the landing page reloads. This, I think is because of the last error Handling Code (ErrorDocument 404 /index.php)
Does anyone know what the solution the problem might be??
questions
Why doesnt the first .htaccess code work when hosted?
What may be the issue with the second available .htaccess file??
Do you guys have better .htaccess file? If yes, can you post it here??
Try this .htaccess (Codeigniter Recommended )
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
or
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
In application/config/config.php
$config['base_url'] = 'http://stackoverflow.com/';
$config['index_page'] = ''; # Should be empty
And make sure Controller name, Model names are in proper way. Bcz Linux Host is an Case-Sensitive.
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 have tried to create an .htaccess file to do following:
Direct www.domain.com/name or www.domain.com/name/ to www.domain.com/page.php?id=name
and www.domain.com/name/2 or www.domain.com/name/2/ to www.domain.com/page.php?id=name&pg=2
my .htaccess looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is not for a valid link
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-z0-9-_\.]+)/?$ page.php?id=$1 [L]
RewriteRule ^([a-z0-9-_\.]+)/([a-z0-9]+)/?$ page.php?id=$1&pg=$2 [L]
</IfModule>
The problem is, that when I actually use a slash after name it thinks of it as a directory and looks for pages in www.domain.com/name/.. But I am still able to $_GET the variables based on id and pg.
Can anyone tell me what I have done wrong? I prefer that the URL in the address bar stays clean as www.domain.com/name/2/.
Also i have another question.. I have tried to rewrite the other URLS without luck.
If they write: www.domain.com/page.php?id=name&pg=2 and want to change the address bar URL to be be clean again, but that completely went wrong for me. Is there any specific way to do this by using what I have already made?
Thanks in advance for your help.
EDIT
The solution was based on PHP and not .htaccess. The answer was found based on this question: Stylesheet does not load after using RewriteRule and include . My problem was caused by PHP including relative to the public URL and directory. I have been forced to define a main URL variable to place before any foreign includes.
RewriteCond is only applicable to the very next RewriteRule.
Have your code this way:
RewriteEngine On
RewriteBase /
# If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
# If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+page\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]
RewriteRule ^([\w.-]+)/?$ page.php?id=$1 [L,QSA]
RewriteRule ^([\w.-]+)/([\w.-]+)/?$ page.php?id=$1&pg=$2 [L,QSA]
I've got a problem trying to install Social Engine. Upload all files, set directory permissions, but when I enter my domain, I get a:
Not Found
The requested URL /install/install was not found on this server.
It's something related to the .htaccess files in root and install directory, 'cause removing them I do begin the installation process BUT with long URLs, this way:
/install/index.php/install
And that's something that would end up with all long URLS, instead of short ones that google use to index, for example. My ISP has safe_mode OFF, and mod_rewrite ON, so I'm just kinda lost...
.htaccess :
# $Id: .htaccess 7539 2010-10-04 04:41:38Z john $
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
# sends requests /index.php/path/to/module/ to "index.php"
# AcceptPathInfo On
# #todo This may not be effective in some cases
FileETag Size
Had the same issue running SocialEngine on Vagrant (using https://box.scotch.io/) and fixed it by clearing the .htaccess file under /install/.