I have a project where I need to mask the url.
Before: example.com/pogi/ako/
After: example.com/ako/
The application is created using codeigniter. Thoug the one found on the sub-directory have another webservice created with codeigniter as well. I tried doing some configurations I know with .htaccess and httpd.conf, but I was not able to make it run.
In the file "application/config/routes.php" add the line:
$route['ako'] = 'pogi/ako';
This will make is so that any request that comes through to example.com/ako will actually go to example.com/pogi/ako but it won't look like that.
Hope this helps!
You may want to remember how Codeigniter Handles URLs, you mentiond Sub Directory in your Question which also is Codeigniter Based Web Service !
When you are Running first Codeigniter App it will Catch your requested Url and get the related Controller and it's Method to Handle it !
Your Controllers can be nested in Sub Directory too ! also as #Ross Mentioned in his answer, this behavior can be override using Routes !
Related
I'm working on an application using php framework Laravel.
I've encountered a problem since I need to open a modification form with two parameters. I pass them in my url like so:
<tr class="beBlack" onclick="document.location = '/showGriefs/{{$data->No_Grief}}/{{$data->No_Employe}}'">
(I know that it is sketchy to create a link within a table but I need the url to change according to which row is clicked/selected)
and I receive them in the following route:
Route::any('/showGriefs/{No_Grief}/{No_Employe}', 'GriefController#showGrief')->name('showGriefs');
My problem is that I don't want my url to change, because, with these url changes, my application can't find the files (CSS, JS and Plugins). And since laravel is using the public directory to store all those files, it's destroying my page. The only errors I get are some missing files error.
I've searched the internet a lot but didn't found anything, I hope you'll all be able to help me. Thanks.
I know 2 solutions to fix your problem. No need to change route URLs. Just fix asset problem.
1. Use / before asset url
If you use / before url, browser will try to look at resource on the root dir.
For example: if you need http://example.com/assets/img.png then use /assets/img.png. Changing URLs will not affect the asset URLs that starts with / character.
2. Use url helpers for asset URLs
asset('assets/img.png') will change asset url from assets/img.png to http://example.com/assets/img.png
I was practicing to work with Yii2 based on the tutorial in this link : http://www.yiiframework.com/doc-2.0/guide-start-databases.html
I am using Advanced Application
These are the files that i have created:
frontend/models/Country.php
frontend/controllers/CountryController.php
frontend/views/country/index.php
now when i try to access it using index.php?r=country/index i get 404 not found error.
But if i move the actionIndex of CountryController to SiteCountroller and rename it to actionCountry and also move my view file inside site folder (and of course change the name of index.php to country.php) then i can successfully see the list of countries using the address index.php?r=site/country
Any ideas about the 404 not found error?
Examples in tutorial are for basic application and contains app\ in namespaces declaration. And you are using advanced application so for frontend it should begin with frontend\ (see for example SiteController in advanced application).
I think this is the reason since you said that file content is exactly the same, you didn't change default configuration and checked folders, files and classes for correct names.
My old website doesn't use a framework and the .htaccess worked fine, take a look at my .htaccess code below:
RewriteRule ^([a-zA-Z0-9_-]+)\.html solution.php?solution=$1 [L]
So the point there is that if it detects '.html' in the url, then the user is redirected to a PHP page passing any GET parameter.
Recently, I have converted my website to use the code igniter framework, so I have converted my .htaccess code to something below:
RewriteRule ^([a-zA-Z0-9_-]+)\.html index.php/solution/index/$1 [L]
I end up getting a page not found. However, if I still manually type
http://myhost/index.php/solution/index/xxx
then it works, but if I type
http://myhost/xxx.html
then it doesn't. My objective here is to maintain the original URL because it is indexed by Google and I do not want the previous visitors of my website to be getting a 'page not found' for my old links.
I need a fix or suggestion that might help. Looking forward to your response. Thanks.
Looks like you missed a lot of stuff while converting your website to use CI. Read about URL suffixes and also note you can use routes to redirect anything you can't handle normally using controllers.
You also need to modify your .htaccess to get rid of index.php since only modifying the config file won't work - there are a lot of resources about that, like this one.
Follow the codeigniter user guide: http://ellislab.com/codeigniter/user-guide/general/urls.html
Specially in following section:
Removing the index.php file
Adding a URL Suffix
If still having problem then check this wiki:
https://github.com/EllisLab/CodeIgniter/wiki/Removing-index.php-in-codeigniter-xampp-for-windows
or
How do I write a .htaccess file to make CodeIgniters URL routing work?
I have a revision website, it has stuff for multiple school subjects. I am starting to develop subject pages, these will have stuff only for that subject. e.g. a physics page
Anyway, what I am trying to do is let people type in www.myWebsite.com/history or www.myWebsite.com/ict - or what ever. And them get redirected to the appropriate page.
From that it sounds really simple, I would just put a file called history.php in my public_html home directory, right?
But my home directory is super organised, with everything in nice sub folders. I want to but all the subject pages in a sub folder called 'subjects' (imaginative name :p ).
How can I put these pages in the sub folder, yet still let the user access them from the URL examples above?
A great way to do this is to use a Front Controller. You can re-route all requests to one file (typically index.php) via htaccess and then from there grab the URI (the /itc, /history etc.) and use it to direct the request to the appropriate script.
Check this out, should get you started.
http://www.technotaste.com/blog/simple-php-front-controller/
Once you figure that out, you will want to compare the differences between dynamic and static invocation. Cheers.
you've got to do a url rewrite for the same. google out mod_rewrite and you'll get the examples.
If you are running under Apache, mod_rewrite is probably the most direct approach to accomplishing this.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Basically create a .htaccess file in the root that maps the URI segment to the appropriate php file in your 'subjects' directory.
I think this is a case where you could use mod_rewrite, so the web server you're using will redirect the user to the appropiate directory. You can either keep the rewrite list manually or dynamically using regexes.
I have two subdomains pointing to the "web" directory in my Symfony 1.4 implementation and would like to route to certain modules/actions based which subdomain was used to arrive at the site
sub1.domain.com --> module1/action
sub2.domain.com --> module2/action
Is there an easy way to do this in routing.yml? Customize index.php, parsing the host for subdomain?
Take a look at this chapter in More With Symfony. It does essentially the same thing by creating a custom route that checks the subdomain... It uses the DB but you could omit that if you dont need to hit the DB.
I'd rather write an execution filter or custom routing class.
Check out this example: http://www.symfony-project.org/more-with-symfony/1_4/en/02-Advanced-Routing