I am having this in a .htaccess:
RewriteEngine On
RewriteRule ^videos/([0-9]+)/?$ vis_film.php?id=$1 [NC,L]
My page is
root/directory/directory/videos/vis_film.php?id=2
but i want it to be
root/directory/directory/videos/2/
And ive placed the .htaccess file inside videos/, is that right? and what have i done wrong?
If you’re already in videos/, you need to remove that path prefix from your pattern:
RewriteRule ^([0-9]+)/?$ vis_film.php?id=$1 [NC,L]
You need to put it in the 2nd directory (root/directory/directory/videos/)
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]
my first page in my website called index.html
when I put in the address bar :
http://websit/index.html it works
but
now my boss asked me that he wants the name just http://websit/index
how can I do that?
Standard web server behavior is to just load the "index.html" file as the root file of a path call. Meaning this:
http://websit/
Is the same as this:
http://websit/index.html
Doing something like this (below) will only cause more problems since it would seem that index is a path instead of a file:
http://websit/index
So any if you want to clean things up just make any reference to http://websit/index.html just http://websit/
If you are using Apache, then, you need to check if Mod Rewrite is enabled, and then, read articles about .htaccess and mod rewrite.
The solution:
Create a file with this name exactly .htaccess on root directory (where the index.html) is there. Then, copy this code (paste it inside the .htaccess file) and test it again using website/index without .html
#comments
RewriteEngine On
#base directory for this file, if its root, then its one /, if its test then its /test
RewriteBase /
#if the URL for the resource that requested is not exist as file
RewriteCond %{SCRIPT_FILENAME} !-f
#if the URL for the resource not exist as directory
RewriteCond %{SCRIPT_FILENAME} !-d
#then it anything types after the website/() redirect it to ().html
RewriteRule ^(.*)$ $1.html [NC,L]
#the ^ and $ used for matching whole string (from beginning to end)
#the () used for grouping matching strings
#the . used for matching any character
#the $1 represents the match group, for our example we used one () then its $1
[1] http://httpd.apache.org/docs/current/howto/htaccess.html
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.
Hey guys, here's what I'm attempting:
I'd like to make it so I can turn all url variables and values into folders, all with one rule. I was expecting to find some way to do this:
www.example.com/var1/val1/var2/val2/varN/valN
In an ideal world I could get rewrite to this:
www.example.com/index.php?var1=val1&var2=val2&varN=valN
But I'm also happy to do something like this:
www.example.com/index.php?path=/var1/val1/var2/val2/varN/valN
And then work them into an array or structure in PHP. In my case everything works through index.php so that's a constant.
Is there any way to do this? I can't find anything through google and apparently I can't figure it out for myself!
Thanks guys :-)
This is something copied almost verbatim from a <Directory> directive in my main apache config. I have been unable to do so, but ought to work in .htaccess as well (probably without the <Directory> parts).
<Directory /path/to/document/root/>
RewriteEngine On
RewriteRule ^(.*)$ index.php?path=$1 [QSA]
</Directory>
The URL http://www.any.com/foo/bar/baz/spam/eggs should become http://www.any.com/index.php?path=/foo/bar/baz/spam/eggs
Try this rule:
RewriteEngine on
RewriteRule !^index\.php$ index.php?path=%{REQUEST_URI} [L]
That will rewrite any request except for index.php to index.php.
And if you want to exclude existing files and directories, add these RewriteCond directives to your rule:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !^index\.php$ index.php?path=%{REQUEST_URI} [L]
And here’s a rule for the former format, except that the parameters have the form var[]:
RewriteRule ^([^/]+)/([^/]+)(.*)$ /$3?$1[]=$2 [N,QSA]
Gumbo, I'm really liking this solution, it works perfectly:
RewriteRule ^([^/]+)/([^/]+)(.*)$ /$3?$1[]=$2 [N,QSA]
I get the feeling I need to stick something like !(js|css) in there to exclude those folders, but I can't figure out where, I've tried a couple places to no avail. Do you have a tweak for that? Thanks again for the killer solution!
Edit: I figured it out, or found it rather!
I put this before the rewrite rule:
RewriteCond %{REQUEST_FILENAME} !^(.+).css$
RewriteCond %{REQUEST_FILENAME} !^(.+).js$
Finally, it looks like this, and works perfectly:
RewriteCond %{REQUEST_FILENAME} !^(.+).css$
RewriteCond %{REQUEST_FILENAME} !^(.+).js$
RewriteRule ^([^/]+)/([^/]+)(.*)$ /$3?$1[]=$2 [N,QSA]
My favorite aspect of this solution is that I can pass url arrays, so:
www.any.com/var1/val1/var1/val2/
Actually creates
$var1= array("val1","val2");