I am attempting to move to nginx...
I have an app running in apache using the following mod_rewrite commands:
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/([a-z\-0-9]+)/(.*)$ /$1/index.php/$2 [E=USERKEY:$1,L]
The PHP backed we are using processes items in the form of:
/[USERKEY]/index.php/[module]/[action]/[etc...]
We want to pass every hit (where there is not a static file on disk) to the index.php file for processing in a format where:
http://www.myapp.com/bobsmith/rockstar/add?q=45678
would translate into:
/var/www/some_static_path/bobsmith/index.php/rockstar/add?q=45678
I know some CMS products do something similar and I located a lot of examples but we have this odd USERKEY payload (which is part of index.php's path) causing issues for my configuration. Additionally, I struggled dealing with the slash (/) after the index.php. The error logs would show:
"/bobmsith/index.php/login" failed (20: Not a directory)
When attempting to browse to: http://www.myapp.com/bobsmith/login
I have tried working with rewrite, if(s), different types of location regex, try_files, fastcgi_split_path_info... I cannot find the cocktail for success!
any/all help appreciated; thanks all!
Related
I am running an Apache 2.4 webserver.
I have a file: http://192.168.0.12/test/index.html
Right now, if I access this file, it displays this in the address bar:
http://192.168.0.12/test/
All I want, is for it to instead display this:
http://192.168.0.12/test
Edit: I decided to get around the problem by instead storing everything I needed from the /test/ directory in the /test-content/ directory, and changing the /test/index.html file to just /test.html
Edit the .htaccess file and add the below rule:
RewriteEngine On
RewriteRule ^test$ /test1/ [L]
I'm working on a database site now that has the URL structure:
example.com/f.php?id=12
I'd like to have
example.com/f/12
I see this all over the place (IMDb, Wikipedia..) but I can't work out how it's done.
Thanks for any help!
They are called vanity URLS and you can do it with htaccess.
http://www.youtube.com/watch?v=oqg6Chk6L7M
What you're looking for is mod_rewrite. It is defined in the .htaccess file located at the webroot of your server. Check out this article -> http://www.sitepoint.com/apache-mod_rewrite-examples/
Its done using Apache's mod_rewrite. For that example of yours you have to create a .htaccess file in the root folder with the following lines:
RewriteEngine On
RewriteRule ^f//?(.*)$ f.php?id=$1 [NC]
this will present "example.com/f.php?id=12" to "example.com/f/12" and "example.com/f.php?id=12/" to "example.com/f/12/". So it can do with a little teaking. But you get the idea. There are many examples out there, with a minute of googling I came across this.
I have this site which uses multisite manager for minisites.
The issue i am having is that my minisites are in subfolder of the main site and when i use
{path='minisite/group'}
it creates a path like this
/index.php/minisite/group
when in fact i need the following
/minisite/index.php/group
is there a to make it aware of the baseurl for the minisite being in a subfolder.
One way to get around this would be to remove "index.php" from your URLs. This is a common task in ExpressionEngine development. There's a great how-to on removing "index.php" from your ExpressionEngine sites here. I've also used the following code in my .htaccess file to remove the "index.php":
# If you can't access the control panel at the folder level (ie "http://site.com/system/"), uncomment the following line.
# DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?/$1
After removing "index.php" from your URLs, you should be able to use {path="} without error. Let us know if this isn't the case.
I want to clear my url with codeigniter, I have these types of urls:
www.ggg.com/index.php/page/8/name.html
and I want to trasform these like
www.ggg.com/index.php/name.html or www.ggg.com/name.html
Is this possible modifying the file route.php?
Actually to get rid of the index.php you need to edit out the index.php file from config.php (in your config folder inside application).
.htaccess for clean urls:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
and to get rid of the .html just eliminate that 'suffix' again in the config/config.php file.
That should be all you need, the .html ending is just for show
As far as turning something like page/8/name into name, I would think twice about how that would work, your page or 8 most likely mean something, so your name would have to have code making it unique. My guess is that page = 8 is the value, and the name is just for the friendly url look.
Edit the routes.php file and add the line:
$route['name'] = "page/8/name";
This is all explained in the docs: http://codeigniter.com/user_guide/general/routing.html
To remove the index.php you will need a .htaccess file. There is an example in the ci docs or google it and you will find loads of tutorials. I'm sure there are even some examples here.
I'm almost finished developing my large project, however I would love it if I could make it so instead of having the users profile pages at: http://example.com/profile/username/USERNAME
(i'm currently using .htaccess to rewrite the GET data into forward slashes and profile(.php) being read as just 'profile' profile.php also parses the url correctly to retrieve the GET data)
But it would be some much better if I could do it so that it's like http://www.example.com/USERNAME (preferred) or http://www.USERNAME.example.com
Any ideas or resources?
Thanks,
Stefan
In your .htaccess in the root, add
RewriteRule ^/([^/]+)/? /profile/username/$1
This matches paths that don't include a slash (so no directories in the path) and suffixes the path to /profile/username/. The path can include an optional final slash.
(+1 for the comment about namespaces - it's a little dangrous having usernames in the root of your site. I've tried to limit the impact of this by only giving out the namespace comprising a single directory. Paths with multiple directories will be handled as normal.)