I have this single page app made using AngularJS and it resides in the document root: http://example.com/
The API that Angular interacts with is created with CakePHP and is located in a subfolder called api. It's accessed via http://example.com/api/xxx.
Apart from acting as an API, the CakePHP application also has an administration backend. In the current URL structure, it's accessible via http://example.com/api/admin. To make it look neater I want users to be able to access it via http://example.com/admin.
What htaccess and IIS rule will I need to achieve this? I'll be testing on both platforms.
Thank you.
You mean http://example.com/admin I assume.
In htaccess you can do it like this:
RewriteEngine On
RewriteRule ^api/admin(/?$|/.+) /admin$1 [QSA,L]
Demo here: http://htaccess.mwl.be?share=d8c07577-d6fb-501d-8e32-403531d471a1
Related
How can i redirect video streams to another domain using htaccess? I am building a application where i can customize m3u playlists containing movies, series and live tv. I am writing a xtream-codes api emulator, so basically i am returning a different playlist (minimized / edited) - but i want the htaccess to redirect the streams request to the origin.
The playlist / api urls look like:
/player_api.php?username=user&pass=pass&action=get_live_categories
The stream url's look like:
/user/pass/streamid.ts
I tried redirecting with php, but this is not the way to go. I also tried to do a redirect on dns level - but thats not good because i can only redirect a complete domain / subdomain
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([-a-zA-Z0-9]+)\.iptv-manager\.xxx$ [NC]
RewriteRule ^((?!index\.php$).*)$ http://player-api.iptv-manager.xxx/index.php?subdomain=%1&route=$1 [QSA,P]
The above code routes any subdomain (wildcard) and route, which is then processed by the php code. But i cant seem to route the video streams through php.
[edit]
As a little bit more explanation of what i am trying to build: Im trying to create a alternative for the Xtream-Editor online playlist editor. Because of the way Xtream-Codes api works - it will get the base url (player_api) and use that with the stream-id's it gets to build a stream url;
As i want to be able to let users not only edit their m3u list, but also provide a customized list in xtream codes api players - if i set the providers host in the initial call to my player_api, it will load the streams and categories from the provider - and not the modified list the user wants to load.
So im not trying to resell streams under a different name - i already made a m3u editor that is widely used, but it is windows based, and requires users to manually update the list when the provider changes their streams.
You need to get it done via php, .htaccess redirect only works for complete domain So use your .htaccess to redirect to php.
.htacess
RewriteRule ^live/(.*)/(.*)/(.*)$ yourphp.php?u=$1&p=$2&c=$3 [L,NE]
RewriteRule ^(.*)/(.*)/(.*)$ yourphp.php?u=$1&p=$2&c=$3 [L,NE]
php files
<?php
$c = str_replace (".ts","",$_GET['c']);
header("location: http://244.117.154.34:25461/".$c.".ch?u=".$_GET['u'].":p=".$_GET['p']."",false, 307);
That what you do to redirect xc to m3u or json to m3u
I am able to reach my website at a certain ip address and I am going to implement a REST service. I have some PHP files that perform actions on a database and I am calling them from the client. I am using linux ubuntu as server and so far I can do this:
http://xxx.xxx.xxx.xxx/api/create/?id=someId&val=someValue
http://xxx.xxx.xxx.xxx/api/delete/?id=someId
I can do the above because inside /var/www/html I have a folder called api that contains another folder called create. The create cointains the file index.php so that I can omit it and execute the URL you can see above.
This works fine but I don't think this is the proper way to do it. I am new with this so I don't know what to do. After some researches I have found that my goal probably be achieved using an .htaccess file use url rewriting but I am not sure.
How can I do this? Do I have to place all the php files in a single folder and then use an htaccess file? (^)
(^) To be more precise: instead of having this
http://xxx.xxx.xxx.xxx/api/create/index.php?id=someId&val=someValue
http://xxx.xxx.xxx.xxx/api/delete/index.php?id=someId
//and so on with other actions...
Do I have to create a folder like
http://xxx.xxx.xxx.xxx/files/
containing all my php files (create.php, delete.php, view.php...) and the use an htaccess to redirect?
I see that websites offer their api using www.domain.com/api/something/?data=Value or www.domain.com/api/something/dataAbout/. Are they doing what I have said about the .htaccess? I hope I have well explained my problem.
htaccess:
RewriteEngine On
RewriteRule ^api/([\w-]+)/?$ files/$1.php [L,NC]
This is inside /var/www/html and I have api inside /home/username/api .
Thanks Emma
Do it like this:
Create php files in a folder files/ subdirectory as create.php, delete.php, view.php etc (by renaming each individual index.php file, you mentioned).
Move away api directory somewhere outside site root.
Once that is done use following .htaccess file in /var/www/html/:
RewriteEngine On
RewriteRule ^api/([\w-]+)/?$ files/$1.php [L,NC]
Then use new URLs as:
http://xxx.xxx.xxx.xxx/api/create?id=someId&val=someValue
http://xxx.xxx.xxx.xxx/api/delete?id=someId
In first, this is not the right way to create a RESTFUL API. My suggestion is to you read a best practices article.
You shouldn't create a CREATE and DELETE folder. You should use HTTP actions.
To create a new record you should use POST. In example, POST /user and in the body you pass the user's information.
In another example, you could use the same route by using different HTTP methods: DELETE /user/1 to delete a user and PATCH /user/1 to edit some already existent user's information.
Hope it's help you.
We have created a bunch of landing pages on a Joomla CMS system, such that the URL for each landing page is www.domain.com/page1.html and www.domain.com/page2.html, and so on. Of course the page1.html isn't really an HTML file it is a dynamic CMS page, just rewritten with htaccess.
The goal is to have one of our other domains, something like www.uniquedomain1.com show the content of www.domain.com/page1.html. Or, another domain like www.uniquedomain2.html show the content of www.domain.com/page2.html.
This needs to be search engine friendly so we can't use URL masking. Also we can't use HTACCESS redirects as this actually changes the URL in the browser bar. Need to keep the www.uniquedomain1.com URL in the browser bar.
Tried Apache VirtualHost options without any luck. You can park in a directory but not from a URL.
Ended up parking the domains on one folder, and then creating a PHP script to detect the domain host and then use CURL to query the correct url and deliver content. This whole thing seems ridiculously over complicated, and of course CURL isn't the best option, but it is all we could get to work.
Any thoughts on how to do this, or a better solution?
You can use HTACCESS redirect rules to do it without performing a redirect.
Change the html file names to be the domain name of the desired domain like domain.tld and do something like this in an .htaccess file
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?([a-z0-9\.-]+\.[a-z]+) [NC]
RewriteRule ^$ /%1.html [L]
A quick test of this worked for two of my test (sub)domains test.domain.tld and test2.domain.tld. Both properly redirected to files with the names test.domain.tld.html and test2.domain.tld.html without modifying the URL.
You could also just use your PHP wrapper script to grab the content of each of the miscellaneous html files and output them.
If you renamed all of your HTML files (as in my previous suggested answer) to be domain.tld.html you could do it fairly easily. Something might look like:
<?php
require($_SERVER['SERVER_NAME'] .'.html');
My situation:
We have a mobile version of our website, and want to start redirecting mobile users to it. The plan is to do this in Apache httpd.conf or .htaccess, using something like this:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (iPhone|Blackberry|...)
RewriteRule (.*) mobile/$1
However we want there to be a way for users to override our default action of redirecting them. One way we thought to do it was to show a link on the mobile site directing back to the regular site, and store a cookie when they use that link.
Could the Apache configuration file check a cookie before redirecting?
Is there a better way?
The HTTP_COOKIE server variable contains the cookies passed from the client to the server. You can look in there to find out what cookies have been generated by a script or module.
How would I go about making my site use organic urls (like http://www.mysite.com/aboutus) - i don't want to use a CMS - my site is powered from index.php is there anyway of getting the text after the / so that I can select that page from the database? I'd rather not do /?aboutus
Thank you :D
You have to use a URL Rewrite engine.
Apache HTTP Server provides URL rewriting through the mod_rewrite module. You may want to check out these articles to get started:
Added Bytes: URL Rewriting for Beginners
Apache: URL Rewriting Guide
You can use mod_rewrite as others suggested. For example the following will map http://my.site.com/page to http://my.site.com/index.php?module=page
RewriteEngine on
RewriteRule ^/([a-z0-9]+)/?$ /index.php?module=$1 [L,QSA]
If you would like to use RESTful URLs throughout your site, here is a handy reference from microformats.org: rest/urls