All controllers return 404 of Cpanel excempt SiteController actionIndex - yii

i upload all of my web folder to the root
and then move all my project to inside a folder
and fixed all the addresses in the main index.php
every thing works fine but i dont know for what reason this happens
But:
class SiteController extends Controller
{
public function actionIndex()
{
return $this->render('index');
}
public function actionTest()
{
echo 'awdaw';
}
|
but site index Works fine

i found the solution in my htaccess file in the end my .htaccess become this and it is ok right now
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?myaxagent\.com
RewriteRule ^(.*)$ https://www.mysitetesttest.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

Please check your htacess file and try to call using controller/action. Here in your case it will be site/test

Related

Redirect loop in codeigniter

I have a site on my https://mydomainname.com.
While working today i had to change permission of a file to make or writable (although i dont think any problem was caused due to this ) and since then the site has gone into a redirect Loop. Site is built Up in php using codeigniter Framework.
My directory structure is :
/var/www/html/myprojectRoot
My server's default DocumentRoot is /var/www/html/
inside html i have .htaccess file as follows :
RewriteEngine On
RewriteRule ^$ /myprojectRoot/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|javascript|images|robots\.txt)
RewriteRule ^(.*)$ /myprojectRoot/index.php/$1 [L]
My baseurl is set to https://mydomainname.com
I can see in firebug console that the sute is being redirected between
https://mydomainname.com and https://mydomainname.com/myprojectRoot
Can someone explain the issue.
Keep your /myprojectRoot/.htaccess like this:
RewriteEngine on
RewriteBase /myprojectRoot/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
then inside /myprojectRoot/application/config/config.php you need to have these config settings:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
Your root .htaccess should be like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!myprojectRoot/).*)$ /myprojectRoot/$1 [L,NC]
i think it is not the issue you might change the code.
You should check the code where you are performing your redirect function.
And there it redirects there might be a check to go in else it will take back from where its redirected.
And it become a redirect loop. From one method to another.

Why is this RewriteRule not working? (xampp)

I have set up this very simple .htaccess-file in my projects root folder c:\xampp\htdocs\myproject\
RewriteEngine on
RewriteRule ^(.+)$ test.php?stuff=$1 [QSA,L]
as well as a test.php (there is no index.php)
<?php
if (isset($GET_['stuff'])) {
echo $GET_['stuff'];
} else {
echo "not set";
}
When I visit localhost/myproject instead of redirecting me to test.php it just lists the directory structure of my project.
When I change the htaccess to something like
RewriteRule ^(.+)$ http://www.google.de [L]
everything works as expected. What am I doing wrong?
Reason why you get directory listing because your URL localhost/myproject actually sends an empty per-dir URI when .htaccess is placed inside /myproject/.
You URI pattern is (.+) that obviously won't match an empty string hence rules doesn't fire and since you don't have index.php or index.html, you get directory list.
Correct rule should be:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ test.php?stuff=$1 [QSA,L]
PS: Note that removing RewriteCond will invoke test.php for localhost/myproject but it will be internally invoked as test.php?stuff=test.php&stuff=

ZF2 Rewrite for Subdirectory / Url Routes

My public folder is within a sub-directory. So I am using two .htaccess files.
The first one outside of the public folder directory is:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [NC,QSA]
The second one inside the public folder is the default Zend one:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
When I go to http://mydomainname.com/myappname I get the following error:
A 404 error occurred
Page not found.
The requested URL could not be matched by routing.
,but this works of course when I go to http://mydomainname.com/myappname/public
I am not sure whether my .htaccess needs to be fixed or if I need to fix my routes
I think the simplest solution would be to move the content of your public folder to its parent directory.
Copy
myappname/public/css
myappname/public/images
myappname/public/js
myappname/public/index.php
myappname/public/.htaccess
to
myappname/css
myappname/images
myappname/js
myappname/index.php
myappname/.htaccess
Make sure you replace myappname/.htaccess with the default zf2 public/.htaccess
Then in myappname/index.php comment out:
//chdir(dirname(__DIR__));

yii : how to config SEO friendly url at Yii?

I create a app by yiic. and then I tried to make a SEO url. I uncomment urlManager at [app root]/protected/config/main.php . And I add following into [app root]/.htaccess.
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
When I browse [app]/site/index, I got the error 404 - object not found. But if I browse by [app]/index.php?r=site/index, it is show me my app page. I followed many web sites by googling. but I got same error.
please help me to solve this one.
Try to use this :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
Instead of using .htaccess you can use urlManager in Yii to have custom url rules. Take a read at urlManager for details. I hope this post might also help to give you the idea. Controlling url in Yii: controller/action/id to /id
I found the solution by myself.
1. uncomment urlManager at app/protected/config/main.php
2. create .htaccess file under app/ folder. (Important : not under app/protected/ folder)
3. copy and past the following code into new .htaccess file
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
That all. Thank you for your helping me, everybody.
Check out this article on URL rewriting in Yii
Also, in your config, set showScriptName to false
'urlManager'=>array(
'urlFormat' => 'path',
'showScriptName' => false,
...

mod_rewrite prefix problem

I'm having some difficulties with mod_rewrite. My directory structure (part of it) is:
index.php
.htaccess
app
controllers
models
views
...
public
javascripts
stylesheets
foo
bar
So, as you can see, all static files are in app/public. That's the reason I would like to route requests like:
http://www.example.com/images/logo.png => app/public/images/logo.png
http://www.example.com/javascripts/app.js => app/public/javascripts/app.js
http://www.example.com/uploads/blog/something => app/public/uploads/blog/something
If that file doesn't exist, then it should route to index.php, like:
http://www.example.com/news/show/42 => index.php
(Because file app/public/news doens't exist)
So, this is my current .htaccess, but I think it can be done in more elegant way.
RewriteEngine on
RewriteRule (png|jpg|gif|bmp|ico)$ app/public/images/$1/$2.$3 [L]
RewriteRule ([^/.]+).js$ app/public/javascripts/$1.js [L]
RewriteRule ([^/.]+).css$ app/public/stylesheets/$1.css [L]
RewriteRule ^(.*)$ index.php [NC,L,QSA]
Also, problem with this one is, it only handles images, javascripts and stylesheets, but not all other files.
I know there is:
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
But, I don't know how to route them with prefix "app/public/"? I tried:
RewriteCond app/public/%{SCRIPT_FILENAME} !-f
RewriteCond app/public/%{SCRIPT_FILENAME} !-d
But it doesn't work! I also tried using RewriteBase, but it didn't work out.
EDIT:
I'm using mod_expires, and I'd really like to automate requests like:
http://www.example.com/images/logo.42.png => app/public/images/logo.png
http://www.example.com/javascripts/app.42.js => app/public/javascripts/app.js
So, as you can see, I would like to have optional number between filename and extension, and that number should be ignored (it is only used for future expires).
Previously, I found:
RewriteRule ^(.*)\.(\d+)(_m_\d+)?\.([^\.]+)$ $1.$4 [QSA]
But I don't really understand how it works and does it always work in my example (multiple extensions maybe)?
Thanks!
Try this instead:
/.htaccess
RewriteEngine on
RewriteRule ^$ app/public/ [L]
RewriteRule (.*) app/public/$1 [L]
/app/.htaccess
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
/app/public/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
Finally, create an index.php in your /app/public/ and put a dispatcher here:
<pre>
<?php
function dispatch($action, $request) {
echo 'action: ' . $action;
echo "\nparameters: " ;
print_r($request);
}
$fragments = explode('/', $_GET['url']);
dispatch($fragments[0], array_slice($fragments, 1));
?>
</pre>
Now say try accessing:
# these will go through php
/controller/action
/post/create
/post/delete/1
# these are static files
/stylesheets/
/foo/bar/myfile.txt