How to write url rewrite in codeigniter - .htaccess

I write the url rewrite in .htaccess in codeigniter as follows
RewriteEngine on
RewriteRule ^Vorarlberg.html$ index.php/users/suchergeb?short_query=true&sbundesland=V&offset=0&limit=25&country=A [L]
RewriteRule ^Tirol.html$ index.php/users/suchergeb?short_query=true&sbundesland=T&offset=0&limit=25&country=A [L]
myproject is located in wamp server under irat.2013 folder
the above code is working but we dont want to show full url, we would like to show
as follows
irat.2013/Vorarlberg.html
and one more thing if we give the full localhost url before the index.php/users... then only it is working other wise it is not.
Please help me ....

Use the application/config/routes.php file. Check docs here: http://ellislab.com/codeigniter/user-guide/general/routing.html

Related

Amend .htaccess path rewrite to include subdirectory

I currently have the following .htaccess rewrite rule setup on my site:
RewriteEngine On
RewriteRule ^([^/d]+)/?$ index.html?id=$1 [QSA]
The rule works in such a way that if I go to the following URL:
http://example.com/dashboard
It won't try and find the dashboard directory that doesn't exist but instead it will keep the URL as is and redirect the user to the root index page. From there I just use javascript to control what view the user will see depending on what path is appended.
The code works exactly as I want it to but i've now had to move my site into a sub-directory on our server. The URL structure is now this:
http://example.com/mysubdir/dashboard
I tried rewriting my rewrite rule to incorporate the directory but have not been successful so far as i'm no .htaccess expert. I tried something along the likes of:
RewriteEngine On
RewriteRule ^([^/d]+)/mysubdir/?$ index.html?id=$1 [QSA]
Could anyone tell me how I can amend my rewrite rule to work in my sub-directory?
You were close - this should do it:
RewriteEngine On
RewriteRule ^mysubdir/([^/d]+)/?$ /mysubdir/index.html?id=$1 [QSA]
Demo here: http://htaccess.mwl.be?share=6e574cc6-90a4-54ca-b113-ce72d6eb5203

How to rewrite url in htaccess without redirecting on localhost?

Trying to ask my question again and explain it the best I can.
I am running WAMP on windows 10. Apache version 2.4.18. My project is in www folder named hoidja.ee. mod_rewrite is enabled, AllowOverrideis set to All.
Inside that folder I have .htaccess file, where I am trying to accomplish rewrite without redirect and it does not work at all. I know the .htaccess file is working, since I can rewrite index.php to /home/ for example and it is working perfectly fine.
I have a page with all the users listing. You can click on the user, and it will take you to a url:
http://localhost/Hoidja.ee/hoidja.php?user_id=94&username=John
How I would like this to show is
http://localhost/Hoidja.ee/user/John
without any redirection.
What I have tried:
#tried first with only user_id
RewriteCond %{QUERY_STRING} ^user_id=([A-Za-z0-9-]+)$
RewriteRule ^hoidja\.php$ /user/%1? [L]
This gave me 404 that /user/94 doesn't exist.
RewriteRule ^user/([0-9]+)/([A-Za-z0-9-]+)/?$ hoidja.php?user_id=$1&username=$2 [QSA]
This doesn't do anything visually. If I enter http://localhost/Hoidja.ee/user/94/John in the url manually, it goes to that page and shows the user data, but if I enter the original url it does not rewrite it. I am using <base> as well.
I have tried all the possible ways but nothing seems to work. How can I accomplish the url rewrite?
You are getting the 404 error because you are rewriting to a non-existent path /user/94 .you will need to redirect /hoidja.php?user_id= to /user/94 and then rewrite /user/94 back to the real location.
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{QUERY_STRING} ^user_id=([A-Za-z0-9-]+)$
RewriteRule hoidja\.php$ /hoidja.ee/user/%1? [L,R]
RewriteRule ^(?:hoidja\.ee/)?user/(.+)$ /hoidja.ee/hoidja.php?user_id=$1 [L]

My htaccess not working in my website but working in testing site

Finally, I managed to write htaccess code and tested it in http://htaccess.madewithlove.be/ and found its correct.
The way the URL is rewritten in this http://htaccess.madewithlove.be/ is working
but when I use the same htaccess code in my website is not working.
new URL http://192.168.1.190/qjyii2/yii2dev3/frontend/web/login.php
Actual URL http://192.168.1.190/qjyii2/yii2dev3/frontend/web/index.php?r=site/login
Htaccess code
RewriteEngine On
RewriteRule ^qjyii2/yii2dev3/frontend/web/([^/]*)\.php$ /qjyii2/yii2dev3/frontend/web/index.php?r=site/$1 [L]
My mod_rewrite is working fine in server. I did put this htaccess under /www/qjyii2/yii2dev3/ and its not working. Any help is highly appreciated.
If you're placing this in /www/qjyii2/yii2dev3/.htaccess then use this code:
RewriteEngine On
RewriteBase /www/qjyii2/yii2dev3/
RewriteRule ^(frontend/web)/([^/]*)\.php$ $1/index.php?r=site/$2 [L,NC,QSA]
.htaccess is per directory directive and Apache strips the current directory path from RewriteRule URI pattern.

.htaccess subfolder not working

I've looked everywhere to try and solve this and I can't get any of the solutions elsewhere to work.
I have a drupal website running on a domain
I have build a new website in www.domain.com/subfolder
In a .htaccess file in the sub folder:
RewriteEngine On
RewriteRule ^/?login$ /index.php?get_action=login [L]
However when I try and visit www.domain.com/subfolder/login I get redirected to the www.domain.com.
I need www.domain.com/subfolder/login to redirect to www.domain.com/subfolder/index.php?get_action=login
How do I accomplish this.
Please help.
I would make use of drupal and instead of using the .htaccess file , I would install Drupal's Login destination module . You can find it here -> http://drupal.org/project/login_destination . I hope it helps .
If your htaccess file is in the subfolder, you can try adding a rewrite base and remove the leading slashes:
RewriteEngine On
RewriteBase /subfolder/
RewriteRule ^login$ index.php?get_action=login [L]
Or, you can explicitly make the target an absolute URL:
RewriteEngine On
RewriteRule ^/?login$ /subfolder/index.php?get_action=login [L]

.htaccess - write a clean URL

I want to write a clean URL for my application. I searched and have written following, but it does not work and gives "Server not found error".
I have URL like this
http://localhost/projectFolder/user_folders/userName/testSite2/
and I want it to be -
http://testSite2.mySystemDomain.com/
I have tried as follows, but it fails.
RewriteEngine on
RewriteRule ^/user_folders/userName/testSite2/(.*) http://testSite2.mySystemDomain.com/$1
EDIT
There will be number of sites like testSite2. I need to write the URL for each such site.
Put this in .htaccess in folder projectFolder
RewriteEngine on
RewriteRule ^user_folders/(.*)/(.*) http://$1.mySystemDomain.com/$2 [R=301,L]

Resources