Is it possible to extract the subdomain part of a domain and use it like a variable in an .htaccess file?
Example
mysub.domain.com
What I'm looking for
(*).domain.com /$
after that the "mysub" is inside the "$-Sign"
Completely I want to route to another subfolder
normally mysub.domain.com routes to the "maindist" folder
now I want to do it more dynamically, so I want to route inside the folder which has the name of the subdomain
mysub.domain.com
normal route->maindist
after htaccess route->mysub
in best case I can do that without notice of the user, so without changing the addressbar from the browser.
Hope somebody can help and explain.
Related
I am not exactly sure the exact words to google.
How do I rename the url link to a simpler one for my webpages?
example:
from:
websitename.com/about_us_what_we_do.php
to:
websitename.com/what-we-do
another example is to let the homepage just show the address
from:
websitename.com/main.php
to
websitename.com/
You can use url rewriting using .htaccess
In .htaccess you have to mention the url that what you want & which will redirect you to actual page.
Exp :
browser url will be: domain_name/what-we-do
& Actual url will be : domain_name/about_us_what_we_do.php
in .htacces you have to mention :
RewriteRule ^what-we-do$ /about_us_what_we_do.php [L]
Check this ref:
I have short the URL Using .htaccess but every shortened URL goes to the same page
This can be done by creating a subfolder with the name what-we-do
and renaming your file about_us_what_we_do.php to index.php.
Then, you'll have your site root directory. Inside you'll have a folder named what-we-do with an index.php file inside.
If you want to do things right, you should look into VirtualHosts ( assuming you're managing the Apache server)
Bellow is my site directory structure:
project-folder/
index.php
Now I have access project using folder name like www.project-folder.com and also www.folder-name.com/index.php
Problem
If some one user enter www.folder-name.com/index.php in URL then redirect on www.project-folder.com using htaccess.
How can I do this ?
Below line is I tried in htaccess
Directory Index public/index.php
Use this on the htaccess file of www.folder-name.com
Redirect index.php http://www.project-folder.com/index.php
To not make confusion, use this kind of redirect:
Redirect /path/to/old/file/old.php http://www.redirectedwebsite.com/path/to/new/file/new.php
I have a subfolder that holds user uploaded files. I want to redirect all direct file requests to this folder to another .php script...so i can check if the user is logged in before i send/show the file to him.
For example:
/mainsite/uploads/user/2324/file.pdf
needs to be forwarded to
/mainsite/uploads/permissions.php
But i need inside the permissions.php to be able to do:
$url = $_SERVER['REQUEST_URI'];
and see what was the initial request...in order to readfile() the file after all the 'checking'.
I've tried this:
RewriteEngine On
RewriteRule ^/uploads/user/?$ /uploads/permissions.php [R=301,L]
but this is just a simple forwarding...i got no idea what file or folder the user requested.
I know i can do this by creating an individual htaccess file inside every folder that is created under 'user/{userid}' but i wanted a simpler function. I dont want to have 10000 htaccess files, if i can do this with just one.
Thanks
try with this syntax: (i added the R=301 part, which wasn't necessary in my version, so it is not fully tested, works without the R option)
RewriteRule "^/uploads/user/(.+)$" "/uploads/permissions.php?file=$1" [R=301,QSA,L]
You can the get your file var in the $_GET array in permissions.php. However, i wouldn't recommend to use directly this value because it can be unsecure. The best way is to only allow fixed values, with a switch for example, having filtered the var as a string before.
I have the following issues with subdomains in my hosting:
I have a subdomain, let's say shop.abc.com
Now I check on my log file, there are people accessing through something.shop.abc.com while subdomain something does not exist.
The subdomain "something" is not just "something" but rather random like xyz.shop.abc.com, rex.shop.abc.com, etc.
Another strange thing is that the rest of the URL is correct, for example, rex4534.abc.com/cat1/article2, "cat1/article2" is the correct URL segment.
Is it possible to redirect these non-existing subdomains to the correct subdomain while keeping the URL segment? Can it be done through .htaccess?
I put this line on .htaccess, but it doesn't work and causes a redirect if I access shop.abc.com
RewriteRule ^ http://shop.abc.com%{REQUEST_URI} [R=301,QSA,L]
Thanks.
simply add " *.shop.abc.com" host and point it to where ever you want.
I am new to Laravel 4. I am trying to generate a URL using the URL helpers. There is a function called url(). It gives me a URL. But it doesn't add index.php to it.
I want a URL with index.php in it. I cannot use route() function because I am using Route::controller('/', 'SiteController'); I don't want to use action() because if there is no index.php it will not generate a URL with index.php.
1) index.php is where the "app" starts and launches.
2) .htaccess rewrites the URL for u.
3) the whole point of URL() is to provide the BASE url of your domain back so that you dont need to hardcode it - therefore you are using it wrong.
4) the only time index.php is there is if .htaccess is not rewriting or not accepted (ie in yahoo share hosting basically) therefor eyou can achieve your index.php/site/index.