I created a zend framework application and the modrewrite only worked when i did:
index.php/dashboard for instance, accessing the dashboard module.
With that being said, I'm working on a new project (not zend framework) that requires a url of: http://server/username. I'm already on the impression that i need to do something like http://server/index.php/username being that it was the only working method for my prior zend framework project.
I have tried several htaccess solutions, and none have worked. They all go to a 404. Here is what I've tried:
RewriteRule /([a-zA-Z]+)$ profile.php?name=$1
RewriteRule ^/([^/\.]+)$ /profile.php?name=$1 [L]
RewriteRule ^/index.php/([^/\.]+)$ /profile.php?name=$1 [L]
RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L]
Nothing seems to be working. Can someone help?
EDIT = I believe the problem is with my apache server. All of these rewrite rules should work. I've looked at httpd.conf and the virtual host configurations. Any insight?
Related
I am sorry to open a replicated question once again but I had no other choice. I am trying to write a clean URL using .htaccess. Here is my code:
RewriteRule ^home index.php [NC,L]
RewriteRule ^about-us about-us.php [NC,L]
RewriteRule ^careers careers.php [NC,L]
RewriteRule ^contact-us contact-us.php [NC,L]
these works very finely. but when I move on to URL's having some GET params like
example.com/providers.php?provider=huawei
and the htaccess rule goes as:
RewriteRule ^providers/([a-zA-Z_-]+) providers.php?provider=$1 [NC,L]
When I navigate to the URL example.com/providers/huawei it throws an error
Notice: Undefined index: provider in directory\providers.php on line x
Appearantly, there is no error in the rule, I have gone through several video and StackOverflow solutions. Some suggested the use of QSA but no luck. I changed my production servers too still negative. Any help in this regard.
TIA
I wrote application using ZF2 and at the end of the project I use some htaccess rewrite rules which let me to remove public keyword from application url. I found this rule in a internet tutorial and it works fine but i tried to add my own mappings and they don't work. Here is my .htaccess file content:
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index [NC,L]
I tried to add rule
RewriteRule ^test-test-test-test-providers$ /providers?localisation=$2&serviceType=$4 [NC,L]
at the last line of file but, after checking, Zend is giving me error that requested URL can't be found in mapping.
Have you tried adding in the public dir:
RewriteRule ^test-test-test-test-providers$ /public/providers
Is there a reason why you remove the public via htaccess? The prefered solution is to set the main directory of your domain to the public folder, as described at https://framework.zend.com/manual/2.4/en/ref/installation.html - there is also a suggestion for a htaccess file. But this is not necessary when the current settings also work.
Zend is giving me error that requested URL can't be found in mapping
This one is important. I assume you mean that the error comes from the Zend Framework (Zend is only a company, it could be also the Zend). That means, that your request goes directly to the Zend Framework. Wouldn't it be better to use your route directly in the route configuration instead of remap it with your htaccess rules?
Could be possible, if the Zend Framework is still using the "test-test-test-test-providers" for it's routing. If so, you should use it in your routing configuration or test a Redirect instead of a RewriteRule; but this means, that the "test-test-test-test-providers" in the URL will be replaced by the "providers".
My .htacces begins with
RewriteEngine on
RewriteBase /
(I tried it also without RewriteBase...)
I tried all of the following rewriting rules to rewrite the URL
index.php?page=news
to
/blog
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/blog$
index.php?page=$1 [L]
RewriteRule ^([^/]*)/blog$ /sites/blog/index.php?page=$1 [L]
RewriteRule ([a-zA-z]+)/([a-zA-z]+)/blog$ index.php?page=$1 [L]
Nothing works - no error. Mod_rewrite is installed and working. I restarted Apache and MySQL everytime I changed something in my .htaccess.
I also want to change my URLs which looks like this... index.php?page=single_news&category=release&id=9&headline=Beastie%20Boys%20III
...into: blog/release/9-Beastie-Boys-III
I am lost. Hope you can help me.
First of all, upload your .htaccess and other files (whole project) to some working, ready hosting server. And check, if your rewriting works OK there. This will let you know, if this is problem with .htaccess or XAMPP itself. I had many strange problems with using .htaccess locally, under XAMPP, that were magically gone, after files were uploaded to Internet hosting.
For example, I don't have working autorization using .htaccess locally, because right after I provide correct login and password I see exactly the same error message as you mentioned. As for me, I'm more than sure that this problem is purely related to incorrect interpretation of .htaccess done by XAMPP (as everything works like a charm on production server), not by some mistakes in .htaccess contents.
I wasted (too) many hours on finding solution and left it. For right now, if I'm developing locally, I rename ".htaccess" to "htaccess", so it is ignored by XAMPP (Apache on-board of it) and re-enable it only when deploing files to production server. This approach maybe isn't to professional, but it saved me a lot of time and stress! :]
On the other hand, if your hosting also fail with the same symptoms, then you'll know, that this is not XAMPP releated problem and you have something wrong with your syntax.
Take a look here for a similar problem reported on StackOverflow.com, where (as I think) the cause is the same as in your issue.
Here's the solution to change links from http://www.domain.tld/index.php?page=blog to http://www.domain.tld/blog is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^\w+$ index.php?page=$0 [L]
RewriteCond %{THE_REQUEST} index\.php
RewriteCond %{QUERY_STRING} ^page=(\w+)$
RewriteRule ^index\.php$ /%1? [R=301,L]
and for links like: http://www.domain.tld/index.php?page=single_news&id=1&headline=This%20Is%20A%Headline
the solution is:
RewriteRule ^blog/(\d+)-([\w-]+)$ index.php?page=single_news&id=$1&headline=$2
After using this code, links looks like this: http://www.domain.tld/blog/2-this-is-a-headline
For your first question, try this:
RewriteEngine on
RewriteRule ^/blog$ /index.php?page=news
This is how my urls currently look:
http://mysite.com/?page=1
How can I make this work?:
http://mysite.com/page/1
There is a post on StackOverflow that asks the same question. But the accepted solution isn't working for me. Because I am using Codeigniter and my page results in a 404 perhaps because since the url pattern of a CI site is:
domain/controller/method
The system is assuming that I am requesting a controller called "page" and a method called "1" both of which of course doesn't exist. Or maybye it's due to a conflict with the other code in my htaccess file (which I downloaded from the CI wiki, it gets rid of index.php and does a few security things). Here is my entire htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users. Additionally this will allow you to create a System.php controller, 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder. This snippet prevents user access to the application folder. Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file, such as an image or css document, if this isn't true it sends the request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
#Pretty urls for pagination links
RewriteRule (.*) index.php?page=$1
</IfModule>
The non indented bit is the solution I got from that other SO question that isn't working for me.
Any solutions to this CI pagination issue?
UPDATE
Ok, read some of the docs and now I have this working:
http://mysite.com/home/index/2
What would be the htaccess rule to turn that into?:
http://mysite.com/page/2
You should make this configuration at /application/config/routes.php (and let the .htaccess just for hide the index.php as you are already doing).
$route['page/(:any)'] = 'home/index/$1';
Or better, like #zaherg remembered (ensures that only numbers could by matched):
$route['page/(:num)'] = 'home/index/$1';
This way all the requests to http://mysite.com/page/2 will be treated internally as http://mysite.com/home/index/2 and so forth.
I suggest you take a look at CodeIgniter User Guide - URI Routing and CodeIgniter User Guide - Tutorial − Introduction.
Good luck.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
from CodeIgniter docs
That will handle removing the index.php, but what happens after that depends how CodeIgniter's query string handling is set up: it can be configured to use a query string rather than a path. See the link for more details.
I really have only a fair idea of what I am doing. Sorry.
This is what I did to rewrite URLs like these:
http://example.com/foo/bar/news/1-category-name/2-item-name
http://example.com/foo/bar/news/1-category-name
into these:
http://example.com/foo/bar/news.php?newsID=2
http://example.com/foo/bar/news-categories.php?categID=1
respectively
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /foo/bar
RewriteRule ^news\/([^\/]+)/([0-9]+)-([^\/]+)$ news.php?newsID=$3
RewriteRule ^news\/([0-9]+)-([^\/]+)$ news-categories.php?categID=$1
</IfModule>
But whenever I try this URL:
http://example.com/foo/bar/news/16-news-category-1/11-title
It always returns a 404 error:
The requested URL /foo/bar/news.html/16-news-category-1/11-title was not found on this server
Why is it trying to find news.html? What am I doing wrong?
I don't know if this is relevant but example.com is virtual (I really don't know the term). The actual files can also be accessed via http://real-domain.com/qux/. So you'd do http://real-domain.com/qux/foo/bar/news/1-category-name/2-item-name to get to 2-item-name.
Does it also help to say that this script actually runs on my development machine?
Development:
PHP v5.3.5
Apache v2.2
Live:
PHP v5.3.6
Apache v2.2
You this code in your .htaccess:
RewriteEngine on
RewriteRule ^news/([0-9]+)-([a-z\-]+)-([0-9]+)/([0-9]+)-([a-z\-]+)(\/?)$ /news.php?newsID=$4 [L,NC]
RewriteRule ^news/([0-9]+)-([a-z\-]+)/([0-9]+)-([a-z\-]+)(\/?)$ /news.php?newsID=$3 [L,NC]
RewriteRule ^news/([0-9]+)-([a-z\-]+)-([0-9]+)(\/?)$ /news-categories.php?categID=$1 [L,NC]
RewriteRule ^news/([0-9]+)-([a-z\-]+)(\/?)$ /news-categories.php?categID=$1 [L,NC]
so when someone goes to:
news/11-category-12 or
news/11-category-12/ or
news/11-category or
news/11-category/
it goes to: news-categories.php?categID=11
and when someone goes to:
news/11-category-12/1-title or
news/11-category-12/1-title/ or
news/11-category/1-title or
news/11-category/1-title/
it goes to: news.php?newsID=1
Also, make sure the .htaccess is at the root of the public_html folder as well of news.php and news-categories.php