Static Url of a web application - php

My web application url is something like http://www.example.com
Now i want that the end user will always see http://www.example.com in there
browser inseted of something like http://www.example.com/index or any thing after the / will not show to the end user
i.e http://www.example.com/abc.php?id='someid'
will display in the user browser as http://www.example.com
Thank You in advance and sorry for the bad english.....

There are several ways to do that. REST web service, URL shortening, changing the alias or creating an .htacces file.
An easy way to do that would be creating an .htaccess file in your root directory.
If you’re running Apache, you can do that by creating a redirect in your site’s .htaccess file. If you don’t already have one, just create a new file called “.htaccess” in your site’s web root.
Save this inside your .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
That rewrite rule basically says, “If a request is coming in that doesn’t map to an existing folder or file, pass it along to index.php instead.”
source http://buildwithcraft.com/help/remove-index.php
and check this htaccess remove index.php from url

Related

User-Friendly Redirect If File Not Exist

I feel like this is a rather common request, but I am too confused about .htaccess and couldn't find a solution by Google.
I have a Laravel instance in a subdirectory of the Apache2 htdocs. Now I would like to invisibly redirect all requests from the root domain to this folder (it should be the "root" website). But the tricky thing is, this is not the only folder, there are other folders directly in the htdocs, which should be reached normally. Just the "root" website is not in the root but also in a subfolder. For example:
https://domainA.com should load https://domainA.com/laravel/public (including possible query string or parameters, but invisibly for the user)
https://domainA.com/websiteB should be served as it is
https://domainA.com/websiteC should be served as it is
...
I assume, part of this solution will be to list all the websiteB, websiteC directories in the .htaccess, would it be possible to automate this?
Thanks in advance!
You can put a .htaccess in the folder you want to custom controle but you have to create some filter condition
<IfModule mod_rewrite.c>
RewriteEngine On
## RewriteBase /foo
## conditions to tell what to redirect ie on URI
## RewriteCond %{REQUEST_URI} ^/a-folder/
## not websiteB or websiteC
RewriteCond %{REQUEST_URI} !^/websiteB/
RewriteCond %{REQUEST_URI} !^/websiteC/
## if the file does not exist call index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ my/path/to/a/script.php [L]
</IfModule>
After you have to do something special in script.php for those HTTP calls
You can also rewrite the URI and pass it again to apache but things can be complicated after...

something messy with .htaccess while using php include

I am currently working on a web application where i want to give user access to their profile by typing www.mysitename.com/username this is working fine with .htaccess but i also want the user to access other pages with clean urls by redirecting
http://www.mysitename.com/song-type-one.php?song=xyz to
http://www.mysitename.com/song-type-one.php/song/xyz
i used the rewrite rule like this
RewriteRule ^(.*)$ ./song-type-one.php?song=$1
RewriteRule ^lok-songs/(.*)$ .song-type-one.php?song=$1
if i type the clean url now in the browser only my main content is loaded the css, javascript and my php include are not loaded. there might be something wrong with my .htaccess whats the best way to achieve all rules i want with .htaccess ?
Try adding this before it:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
If the file exists on disk it won't do your rewrite rule allowing the JS and images to be loaded normally.

Redirect rules for 404 content using .htaccess

It's quite common for us to put in progress sites at www.domain.com/dev/ and then once the client has signed off the site to move it to the top level www.domain.com, what we like is to be able to put a .htaccess file in the top level so that once we've moved the site out of /dev if the client accidently goes to www.domain.com/dev/apage.php that they be redirected to www.domain.com/apage.php, but only if www.domain.com/dev/apage.php doesn't exist.
Sometimes the dev folder will be called various other things, and ideally we don't want to have to edit the .htaccess file to match the folder name.
Thanks for any help.
You could do something like
Edited based on comments:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule dev/(.*)$ $1 [R=301,L]
Which basically means that if the file doesn't exist - RewriteCond %{REQUEST_FILENAME} !-f - then rewrite any request to dev back to the root. You have to specify dev/ in the rewrite rule as otherwise you will get stuck in a redirect loop.
This will only work however if you are using explicit files rather than a framework with everything routed through index.php for example

Two htaccess files

I have a question about using multiple .htaccess files - I couldn't find the answer to this after looking elsewhere on stackoverflow, so I hope you guys can help.
I currently have one .htaccess file in the root of my site, which performs a simple url rewrite:
Options -MultiViews
# CheckSpelling off
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?url=$1 [L]
ErrorDocument 404 /index.php
I'm currently working on the second phase of development of this site, and I've made a replica in a subfolder (e.g. www.abcdef.com/new/). The trouble is, at the moment if I click a link on this replica site, it redirects me to the root, original page, whereas I want it to go to the equivalent page in the new/ folder. I've put another .htaccess file in this new/ folder, which however doesn't have any noticeable effect:
Options -MultiViews
# CheckSpelling off
RewriteEngine On
RewriteBase /new/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /new/index.php?url=$1 [L]
ErrorDocument 404 /index.php
So my question is: is it permissible to have another .htaccess file in a subfolder like this? And if so, why aren't the above lines working?
Thanks in advance for any ideas on this!
It's possible to have multiple .htaccess files, and the system is designed to work the way you want it to.
You're setting RewriteBase, which explicitly sets the base URL-path (not filesystem directory path!) for per-directory rewrites.
So it seems like your requests would be rewritten to /new/new/index.php, a path and directory which probably doesn't exist on your filesystem (thus not meeting your RewriteConds) and such is being redirected to your /index.php 404.
As a test, perhaps try changing the ErrorDocument to:
ErrorDocument 404 /new/index.php
If you see rewritten calls go to this then it might indeed be your RewriteBase.
You say
The trouble is, at the moment if I click a link on this replica site,
it redirects me to the root, original page, whereas I want it to go to
the equivalent page in the new/ folder.
Could it be that you are using absolute links in your pages and not relative ones? For instance if a link looks like "/sample", when in your main site it will link to http://.../sample and the same is true if the link is inside a page under "/new/". If you'd use just "sample" then that would resolve as http://..../sample or http://...../new/sample, depending on the URL of the page.
Having a second htaccess file in a subdirectory shouldn't be an issue, and as far as I can tell, your two look okay.
Are you sure the links in the site are correct? (ex, they are /new/foo, not just /foo)?

Symfony: Options for admin URL

In development mode my symfony admin/backend app can be accessed at http://localhost/backend_dev.php. For production mode, I created a controller php file, admin.php, so now in production the admin application can be accessed at http://www.domain.com/admin.php.
What do I have to do to allow the admin app to be accessed at domain.com/admin or admin.domain.com?
Thanks!
you can open new subdomain an on that subdomain (admin.domain.com) setup virtual host that points to server with your symfony app.
you can look at the full tutorial [here][1].
[1]: http://blog.mirthlab.com/2008/03/04/dynamically-loading-symfony-applications-via-subdomains/ here
You probably are better off putting everything admin like in the admin directory, but you can cheat by using mod_rewrite
RewriteRule ^admin/?$ admin.php [L]
Here are some basic ways you could do it:
Either dump admin.php into a folder called 'admin' in the root of www.domain.com, and rename admin.php to index.php. (Easiest solution)
Of course, this way you have to adjust all relative links in admin.php to one level up (appending '../' to the start of all relative urls should work), as well as all absolute links to reflect the changes.
Regarding your admin.domain.com, you should contact your webhost/domain name provider to setup a subdomain for you.
Or if your webhost allows .htaccess files, you could write a mod_rewrite rule.
i would create a module called admin...then in presumably the index action I would put whatever you had in your admin.php file.
then in your routing.yml file just point yourdomain.com/admin to the admin/index....that way you keep everything within the symfony front controller
Andrew
Make sure your DNS resolves the admin.domain.com correctly, then edit .htaccess in the /web to have mod_rewrite pick up on your subdomain and rewrite requests to admin.php. Optionally rename your admin.php to something less obvious or perhaps do a quick subdomain check inside it as well, or extend the rewrite with a 301 redirect if anyone hits domain.com/admin.php.
The following simple .htaccess works for me:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# The admin subdomain returns the backend
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^admin\.domain\..*
RewriteRule ^(.*)$ admin.php [QSA,L]
# Check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# No?, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Change domain to your own domain.

Categories