My current url is:
http://example.org/dir1/dir2/profile.php?username=someone
I want it to look like this:
http://example.com/someone
My .htaccess file is in public_html folder and it is completely empty.
Please, can you help me?
Try this :
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9_-]+)/?$ /dir1/dir2/profile.php?username=$1 [QSA,L,NC]
The conditions make sure you don't rewrite any existing file/directories on the server.
Related
I've wanted to move my index.php file from the root to /system/ folder, this is for no reason but giving myself opporunity to learn more about .htaccess, which I am finding very confusing.
How can I achieve this? Currently my code looks as follows
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?query=$1
This allows for example mydomain.com/some-url/ to become /index.php?query=some-url for example, this far I'm with it all. But moving the file into System folder and addind /system/ before /index.php does nothing. How does one do this? Thanks!
This could be done with a simple rewriterule. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule ^(.*)$ system/index.php [L]
I have the following directory structure:
root
--/inc
--/img
--/docs
---/public
----/contact
-----/img
------telephone.jpg
-----contact.php
---/private
My aim is to make each folder under 'docs' a 'contained' webpage. Each folder will have it's own /img/ folder, and a /bin/ folder too, which could contain anything from Mp3s to PDFs.
Currently I am routing everything through to index.php, and then manually redirecting the file from there. But this is proving to be very slow. What I was thinking would be faster would be something like this in my .htaccess if say, an image was trying to be accessed via /contact/telephone.png:
try /img/{url_path}
Otherwise, try /docs/$1/img/$2
Otherwise route through index.php
How could I go about doing this? Currently my .htaccess is as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# if file not exists
RewriteCond %{REQUEST_FILENAME} !-f
# if dir not exists
RewriteCond %{REQUEST_FILENAME} !-d
# avoid 404s of missing assets in our script
#RewriteCond %{REQUEST_URI} !^.*\.(jpe?g|png|gif|css|js)$ [NC]
RewriteRule .* index.php [QSA,L]
</IfModule>
Any help appreciated! Thanks
You can do something like this in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
# check if this image path exists in docs/<folder>/img first
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/docs/$1/img/$2 -f
RewriteRule ^([^/]+)/(.+?)/?$ /docs/$1/img/$2 [L]
I have this structure:
http://mywebsite.com/folder/myapp1
http://mywebsite.com/folder/myapp2
http://mywebsite.com/folder/myapp3
How can I do to hide "folder" in the URL using .htaccess?
That is, if I enter
http://mywebsite.com/myapp1
I want it to display the contents of
http://mywebsite.com/folder/myapp1
Thanks in advance!
You can try this. This should work for you inyour .htaccess file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+) folder/$1 [L]
I've moved my abc folder from /myproduct/abc directory to /myproduct/extensions/abc on my server.
How can I redirect all calls to http://localhost/myproduct/abc to http://localhost/myproduct/extensions/abc ?
Ex : if requested URL is http://localhost/myproduct/abc/pqr.php, it should be redirected to http://localhost/myproduct/extensions/abc/pqr.php
Basically I want .htaccess code that can be placed inside /myproduct folder and if someone requests URL like http://localhost/myproduct/abc/pqr.php then it will look for occurrence of /abc/ and replace it with /extensions/abc/
We cannot replace /myproduct/abc/ by /myproduct/extensions/abc/ as myproduct can have white-labelled to yourproduct or myproduct1 etc..
Any help would be highly appreciated. :)
You may try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /(.*)/abc/([^\.]+)\.php/? [NC]
RewriteRule .* %1/extensions/abc/%2.php [R=301,L]
Redirects
http://localhost/Any/Number/Of/Folders/abc/AnyFileName.php
To:
http://localhost/Any/Number/Of/Folders/extensions/abc/AnyFileName.php
To keep the first URL showing in the browser's addres bar, remove R=301 from [R=301,L]
NOTES:
If only folder myproduct/ is needed, like this: http://localhost/myproduct/abc/AnyFileName.php The rule will work too.
If file AnyFileName.php, pqr.php for example, exists at folder abc in the incoming URL, the rule will be skipped (Makes no sense to have it there anyway). The script has to be at folder abc in substitution URL: http://localhost/Any/Number/Of/Folders/extensions/abc/.
Vijay,
Try this:
RewriteEngine On
RewriteBase /
# REQUEST_FILENAME should not be file name
RewriteCond %{REQUEST_FILENAME} !-f
# REQUEST_FILENAME should not be directory name
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /(.*)/abc/(.*)/? [NC]
RewriteRule .* %1/extensions/abc/%2 [R=301,L]
Which server are you using? Have a look at mod_rewrite in case you are using Apache 2.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Having some issues with .htaccess on my website. I'm trying to alter the suffix of the URLs for my website. URLs currently appear as:
www.example.com/about.phtml
I want to remove about.phtml and replace it with about so it looks like:
www.example.com/about
The examples I'm using are not what I need on the website so I would like code that I don't have to go through and specify which specific page to remove it from and rather do it all automatically.
I've tried using php instead of phtml with no luck. Here is the code I am using:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.phtml -f
RewriteRule ^(.*)$ $1.phtml
Any ideas what I am doing wrong here?
FYI: my host is JustHost and they allow me to edit my .htaccess but if anyone has heard of or had any problems with them please let me know, I spoke to their tech-support who couldn't help me any more than I can help myself.
Try this :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.phtml [NC,L]
This works for me:
RewriteEngine on
RewriteRule ^/?([a-z]+)$ $1.phtml [L]
You can Check first your rewrite mode is on or not in apache\conf\httpd.conf file
check below code in httpd.conf file
#LoadModule rewrite_module modules/mod_rewrite.so
if hash exist in above the line then remove hash and restart apache server
After then you can set below code in your cakephp httaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.phtml -f
RewriteRule ^(.*)$ $1.phtml [NC,L]
</IfModule>