imagine the following situation:
i've got a folder on the webserver:
www.domain.com/test/project
in "project", i've got my whole php application. in "project" i've also got the following .htaccess file:
RewriteEngine On
rewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(util/(css|js))($|/) - [L]
rewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(UI/designs)($|/) - [L]
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]
which allows me basically to have url like this for example:
www.domain.com/test/project/admin/user
i've allowed access to "util/(css|js)" for loading the css and js files from ther
but eventually i want to have this url for example:
www.domain.com/test/admin/user
so basically, to just shift the "project" folder....
is this possible with an .htaccess file?
is this also possible with the following example:
www.domain.com/project/admin/user
www.domain.com/admin/user
please help me, i often tap into 500 internal server error :(
i tried something like this:
RewriteRule ^test/(.+)$ http://www.happydomain.org/folder/$1 #[R=301,L]
i've got the solution! =)
this .htaccess must be adden in the "test" folder - concerning my example mentioned in the question
RewriteEngine On
RewriteCond %{REQUEST_URI} !^project/
RewriteRule ^(.*)$ project/$1 [L]
Related
I am currently coding my own website in PHP and MySQL on WampServer (local). I've already rewrited some of my URLs successfully. But I'm having problems with one of them.
I want to display on a page all my articles listed in a category using the GET method. For the moment, I have the following URL : http://localhost/actuco/cat.php?id=xpS3cc&slug=amerique-du-nord and I would like to use and display this URL as http://localhost/actuco/c-xpS3cc-amerique-du-nord/ (which does contains exactly the same GET parameters than the original URL).
I have tried to do this with the following line in my .htaccess file
RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2
When I write the second URL in my browser, it shows me a blank page with no code lines at all. My first URL works perfectly.
I'm really lost and I really don't know how to fix it.
Here is the whole .htaccess file used on my website (all other URL rewritings in this file do work).
Options +FollowSymlinks
RewriteEngine On
RewriteBase /actuco/
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_URI} /+[^\.]+$
#RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ article.php?lng=$1&yr=$2&mo=$3&dy=$4&slug=$5&total_slug=$6
#RewriteRule ^([^/]*)-([^/]*)-([^/]*)$ waluty.php?cur=$1&amt=$2&lang=$3
RewriteRule ^([^/]*)/([^/]*)$ url.php?mode=$1&u=$2
RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2
RewriteRule ^bio$ o.php [L]
Thanks in advance for your help !
just pest this code in your .htaccess file
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
hopefully, it will work.
Solved ! Just forgotten to add slash before $ in this line
Before :
RewriteRule ^([^/]*)/([^/]*)$ url.php?mode=$1&u=$2
After :
RewriteRule ^([^/]*)/([^/]*)/$ url.php?mode=$1&u=$2
Now it works, but I still have a problem with multiple hyphens in slug described here : Multiple hyphen handling in .htaccess (URL rewriting)
One pages of site have such adds: domain.com/posts/name.php
Other pages of site have such adds: domain.com/pages/name.php
I need to cut from these adds posts/ and pages/ only.
Firstly, I tried to use in .htaccess next rules:
RewriteRule ^([A-z0-9-]+)$ /posts/$1
RewriteRule ^([A-z0-9-]+)$ /pages/$1
Don't help.
Secondly, I tried to use in .htaccess such rules and conditions:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ posts/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ pages/$1 [L]
As result: image of mistake 404
Also I tried to use such method:
RewriteCond %{REQUEST_URI} ^([A-z0-9-]+)$/(posts|pages)/([A-z0-9-]+)/$1 [NC]
RewriteRule .* domain.com/%1%3
Don't help....
what i am understanding you need to remove the post and pages from the url following code will help you for that.
You would need the rewrite module of Apache: mod_rewrite.
Then do something like this:
RewriteEngine on
RewriteRule ^post/(.*)$ $1
RewriteRule ^pages/(.*)$ $1
Here is the official documentation of mod_rewrite: click
please test it onece I dint test the code but did same for replacing url and its work for me.
Thanks.
The solution of this problem such:
We enter all information about the page in the MYSQL database:
image of database
We generate a page from the database:
generation of page (php)
Set the generated page for Human-Friendly Url:
file .htaccess
So everything works, and POSTS there are in their folder in the database, and PAGES in their folder.
folder in database
All is clean. If you can do better somewhere, then correct me, please.
I setup .htaccess file as follows to make elegant url by hiding .php extension;
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Now all of my pages work other than following three urls/pages;
www.auroracs.lk/about
www.auroracs.lk/enquiry
www.auroracs.lk/locate
for above URLS I get following error. (You may check online by trying that URL right now)
..............................
Not Found. The requested URL /about/.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
..............................
But if I rename about.php to about1.php then www.auroracs.lk/about1 url works. same happens to other two php files also. Can any one help why its not working only for these three pages. Is it because my .htaccess conflicting with some other file or any advice is appreciated.
Replace your rule by this more correct rule:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
So I'm using the Flight PHP microframework (http://flightphp.com/) to do routing. My question is, how can I run the router from within a subdirectory? What I mean is, essentially, run it 'sandboxed' within a folder.
As in, a request to '/' just pulls the regular index.php file. But a request to '/flight/file' would load the URL using Flight.
I know you can't just dump it in a folder on the server and expect it to work because FlightPHP expects the URLs relative to the root.
Is there a way to run FlightPHP isolated in a directory with the rest of the website running regular PHP?
EDIT
I tried simply putting the .htaccess file into the subdirectory. This has the peculiar effect of causing the routes to still act as if they are from the root (e.g. /thing/otherthing/ when it should be /otherdirectory/thing/otherthing/ ) while simultaneously causing the 404 callback to not work. Not what I intended.
EDIT 2
Contents of .htaccess file, which are what is suggested by the Flightphp website:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
I know this is an old question but I've been doing something similar just by adding something along the lines of
RewriteBase /flight/
in the .htaccess file (before all of your rules) of the flight directory. Hope this helps someone else looking for the same thing. Example:
RewriteEngine On
RewriteBase /flight/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
Sorry for giving you an answer that is not going to help a lot. I'm running Flight (also sandboxing) on a subdirectory. I've created an .htaccess just with the defaults in the subdir and Flight is now regarding this as it's root.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
Did you check the content of the .htaccess on the higher levels, maybe there is something that is blocking you
Hi i am new to codeigniter and using this as my url
http://localhost/codeigniter/index.php/site
and have included following htaccess file
RewriteEngine On
RewriteBase/codeigniter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [PT,L]
after including this htaccess filr to codeigniter folder the web page stops working on both
http://localhost/codeigniter/index.php/site
and
http://localhost/codeigniter
basically i need
http://localhost/codeigniter
to work
please help
Thanks
You are missing a whitespace between your RewriteBase and the base URI:
RewriteBase /codeigniter
This is probably why things has stopped working (a server error status 500, which you could find in your error log).
Use this one,
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
For more details Click Here.
In order to have your codeigniter site default to the site controller you need to update config/routes.php to set the site controller as the default route.
For the rewrite issue see #Repox's answer.