Multiple index files in different folders? - mod-rewrite

I just figured out that if I have multiple folders in my website such as logout and login I can then have a log out/in page within the folders called index.php
Now when someone goes to project.com/login/ it will load up the index.php file in that folder and the url will look nice.
Is there any problem in doing this?

As Candy Pointed out it is better to do this with url rewrite rather heeps of folders and index files. I went and looked it up and you can do a lot of cool things.
for the basics:
http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/
http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html
Instead of creating many folders which would make the site confusing (for the developer) and having numerous index.php files which would also get confusing if you were editing more than one at a time, you can use the apache mod_rewrite module which lets you transparently (the url in the address bar stays the same) redirect one URL to another. You could use this to clean up messy url's and have /login/ instead of /login/login.php or /user/1335591/ or even /user/'username'/ rather than an ugly url which is hard to remember like the following: /user/user.php?user=1335591
to start first put RewriteEngine on in your .htaccess file to turn it on
redirects are then written in the .htaccess file in sequence
Below is an example:
RewriteRule ^products/([0-9][0-9])$ /products/$1/ [R]
RewriteRule ^products/([0-9][0-9])/$ /productinfo.php?prodID=$1
If the user types in products/12 the first rule will append a trailing slash to it. The second rule will transparently redirect this URL to productinfo.php?prodID=12

Related

How to make Apache pass control to Laravel for specific URLs

I have a Laravel route for /ad-reports/ and /ad-reports/promos that worked fine until I put directories matching those names inside public. Why did I do that? I need them for caching, so that a request for (e.g.) /ad-reports/promos/12345.pdf gets handled by Laravel if there is no PDF named 12345.pdf saved inside public/ad-reports/promos, but by Apache if the PDF has already been created and saved there.
I don't want to mess with my URL structure (the whole point of having routing is so we're not forced to let the file system dictate our URLs) and of course I can't afford to give up the caching.
How can I force Apache to ignore requests for /ad-reports/ and /ad-reports/promos, but handle everything that it should handle?
Or alternately (and better, actually) how can I make Apache ignore requests for folders, and only respond to requests for specific files, letting Laravel handle anything that does not match a file inside public?
Remove this line from your .htaccess file:
RewriteCond %{REQUEST_FILENAME} !-d
It tells apache to handle the directory if the directory exists, but you only need it to handle if the file exists, which is done by the -f line.

Wrong redirection to old site after Magento's duplication

I’ve got this problem: Magento redirection problem after moving
I changed local xml, deleted cache, changed secure and unsecure link, everything… It doesnt’ work. The only difference is that I duplicated my installation on the same server and I changed subdirectory’s name for the second installation. But I tried also on another server and is almost the same, except for the fact that it keeps linking me back to Google, and not to old domain.
I noticed that if, on the other server, I don’t change subdirectory’s name everything works (and I don’t understand why) but I want on the same server 2 identical installation with 2 identical databases. How can I? What’s the problem? How can I avoid this wrong redirect?
Magento relies heavily on caching. I've noticed in the past I've had to clear my browser internet cache before the redirects updated.
Also if you cloned/duplicated the code & database, its likely you will have the old URL's in the rewrite module. Have you tried reloading all the indexes after moving and changing the URL's in the magento configuration?
Worst case you may have to change the URL in the core_config_data table in the database.
There is no reindex required for base_url to be taken in account.
Only cleaning cache is required. Are you sure you did it well ?
What cache system are you using ?
What did you changed in your local.xml for this ?
Are you sure you didn't left old information in a local.bak.xml for example ? Magento reads every xml file in /app/etc
I have encountered this when moving, and it ended up being that my .htaccess file still had an old rewrite rule pointing to the old domain. In case someone else has this issue for which the other suggestions to not apply, look for something like this:
RewriteCond %{HTTP_HOST} !^www\.localhost\.com$ [NC]
RewriteRule ^(.*)$ http://www.localhost.com/$1 [R=301,L]
and make sure obviously that the localhost.com matches your domain (the above simply redirects with a 301 permanent redirect rewrite any request that does not begin with www.localhost.com to http://www.localhost.com/ (such as the non-www localhost.com)

Custom URL's to users, dynamically at a scale

I need to create custom urls for my users, for ex: www.example.com/alpha, www.example.com/beta. I was creating symlinked directories, which I think worked as a good starting point for prototyping. However, now I need to do this at a scale, running on several web servers behind a load balancer. I am not sure on the right way to do this.
If you are running on an Apache server and you have access to .htaccess files then try this in a .htaccess file
RewriteEngine On
RewriteRule ^(.*)\.html$ index.php?p=$1
This will point all URL's to index.php?p=* internally.
A user will see the .html, and the server interprets it as the pointed url.
Example: yourdomain.com/cocacola.html -> yourdomain.com/index.php?p=cocacola

Exclude a directory from a rewriterule using ISAPI rewrite 3

Basically I've recently added the below rule in my httpd.conf for ISAPI rewrite on an IIS server to make sure that it always defaults to lower-case file and directory names.
RewriteRule ^(.*[A-Z].*)$ $1 [CL,R=301,L]
This is all fine and dandy for every part of the site except for one directory which we can call /MisbehavingDir, the code in this particular directory is filled with mixed-case filenames and lots of server- and client-side scripting that would have to be rewritten to use all lower-case in order to work properly (with the RewriteRule above it seems to hit a couple of 301s in the wrong places which causes that part of the site to function poorly to say the least).
Since I'm not in the mood for rewriting that part of the site I'd love to find a good way to modify the above regex so that it matches everything except paths starting with MisbehavingDir and since my regex-fu isn't really good enough I figured I'd ask here.
Is there a simple "beautiful" solution to this that anyone wants to share or should I just set aside several days to rewrite the app, then test it and go through that whole dance?
Well, apparently the trick was to add a rewritecond statement that looks something like RewriteCond %{URL} ^(?!/MisbehavingDir/.*$) to make ISAPI rewrite skip the next rule.

Rewriting example.com/folder/path to example2.example.com/path

Actually the thing is that i'm having a sub domain (example.domain.com) which is redirected from other domain of a folder (www.domain/folder) . but need the rewrite rule for my sub domain which shows the url links for the main domain ie., www.domain/folder/path
i need to get as example.domain.com/path. Instead of getting the main domain path i need to expose the URL with sub domain path.
As far as I can tell, there are two ways to do what you are wanting. Both of them require significant extra overhead. Both are also likely to require example.domain.com to lie about who it is.
I wouldn't recommend either if you can avoid it, but.
Method #1
Set up a transparent proxy on www.domain.com/folder to show the contents from example.domain.com. If I recall correctly, this can be done with mod_proxy, but I don't remember how specifically.
Method #2
Set up a rewrite rule on www.domain.com/folder to redirect to example.domain.com. Then set up example.domain.com to either lie about who and where it is, or fix all links in pages on example.domain.com to explicitly go to http://www.domain.com/folder.
In the root .htaccess file on www.domain.com: (to redirect to the subdomain)
RewriteRule ^folder/(.*) http://example.domain.com/$1 [R, L]
Actually the subdomain is created from godaddy account and the maindomain/folder is in other hosting server... masking can be done in top address bar but when i hover through links the actual URL path is displayed in lower left corner of the browser....
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} {HTTP_HOST}[a-zA-Z0-9.-]mydomain/folder/(.)
RewriteRule ^/folder/(.*)$ http://abc.example.in/$1 [L,R=301]
Some one has mailed me the above rewrite rule but still the problem persists...
I have been working on this issue from couple of days and i came to conclusion that
1)From godaddy account i have created a subdomain and forwarded with masking to the actual IP address of the virtual host server, but here comes the problem...
i could not forward to the (domainname/foder) rather i can do it for domainname
So i stuck up here for the solution
If u find a solution i would be considered them as a GENIUS......

Resources