Use ? at end of url without the need for pagename.ext - url

On my website I pass parameters like this:
http://www.mysite.com/somepage.php?action=something
But I would like do just do this:
http://mysite.com/?action=something
How can I do this? Do you know of any good, simple resources around? I can't find any because I don't know exactly what to look for.
Lots of thanks in advance!
jase

The URL you show will usually go to the index file in the root directory (e.g. index.php).
You will be able to catch $_GET["action"] from there without any additional work.

.htaccess
RewriteEngine On
RewriteRule ^([^/]*)$ /somepage.php?action=$1 [L]

Related

.htacces how to write htacces rewrite rule for seo friendly url

I'm just new to .htacces
I want:
example.com/page.php?page=how-to-learn
changed to:
example.com/how-to-learn
I google'd some and tried but no change url.
That's not how .htaccess work : it won't change your links to display the corrected version, but it looks for a match in the expressions you'll write into it to rewrite the correct parameters.
For example, in your code, your .htaccess sould look something like this :
RewriteEngine On
RewriteRule ^([a-z-]+)$ page.php?page=$1 [QSA,L]
If you write example.com/how-to-learn in your browser, you'll be able to see the content of example.com/page.php?page=how-to-learn.
I advise you to be VERY careful though : as the expression is VERY permissive, you'll have to check in the page.php file that the file if legitimately allowed to be loaded.

hide url directory

I have a website:
www.mydomain.com/subfolder/subfolder/index.php
How could always hide the directory names from the url. I mean always hide the 2 subfolders' names from the url as the page changes.
Example:
These urls:
www.mydomain.com/subfolder/subfolder/index.php
www.mydomain.com/subfolder/subfolder/about.php
www.mydomain.com/subfolder/subfolder/contact.php
...
Becomes:
www.mydomain.com/index
www.mydomain.com/about
www.mydomain.com/contact
...
I want to use the last mentioned urls for requesting these pages, too, without typing a horrible long url.
you can find some good hints when you will look for mod_rewrite or mod rewrite in htaccess.
If you have access to the Rewrite engine, you can use a simple rewriting pattern similar to this:
RewriteRule ^/(.*)$ /subfolder/subfolder/$1.php

Rewrite to case insensitive urls in CodeIgniter site?

I'm using CodeIgniter for a web application, and now I have an urgent question: I just discovered that urls are case sensitive in Linux based servers, and I have just moved a site from Windows to Linux. This means links to the site don't work anymore where there are now all lower-case urls, which were not before.
Googling I found that you should be able to do something like this in the .htaccess file:
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
But I tried that and it was not good at all...! Suddenly I got a big ugly error page staring at me instead, saying that there must be something wrong with the Tomcat server or something like that. Needless to say I removed those lines immediately!
But why didn't it work then, and what should I do instead?
Any help would be greatly appreciated.
Code igniter supports regular expressions - if you'd like to be explicit in the definition of your routes, define them in this fashion to be case insensitive:
$route['(?i)(about\/contact)'] = 'about/contact';
If case insensitive routes are required, do below changes to URI.php
Location of File: system/core/URI.php
Find $this->_parse_request_uri() and replace it with strtolower($this->_parse_request_uri())
Actually found out that it was quite easy, surprised that no one answered this (perhaps it isn't the correct way, but I would think so...):
I just added some routes in the routes.php file in the config folder:
$route['About/Contact'] = "about/contact";
And so on...

.htaccess php progress

Thanks to the people that've helped me so far with this, I'm ready for the last step, I think.
I've got my URLs looking like this.
/brochure.php?cat_path=35&name=concrete-intermediate-posts
This is great and finally I just need to know how to turn that URL into this desired URL:
/brochure/35/concrete-intermediate-posts
Just like the Stack Overflow format.
Could anyone help me with the correct .htaccess rule?
Also, if I have other get variables in other sections, will this re-write harm them? (they use different variable names)
Thanks
With mod_rewrite you will rather do the opposite: rewrite a URL path like /brochure/35/concrete-intermediate-posts internally to /brochure.php?cat_path=35&name=concrete-intermediate-posts:
RewriteRule ^([^/]+)/(\d+)/([^/]+)$ $1.php?cat_path=$2&name=$3 [L,QSA]
The other side, using a URL path like /brochure/35/concrete-intermediate-posts instead of /brochure.php?cat_path=35&name=concrete-intermediate-posts in the HTML documents, would be done with PHP.
I Hope you mean something like this:
RewriteEngine On
RewriteBase /
RewriteRule ^brochure/([0-9]+)/([-a-zA-Z0-9]+)$ /brochure.php?cat_path=$1&name=$2 [L]

Mod_rewrite not working properly

I have this in my .htaccess file...
RewriteEngine on
RewriteRule ^/invite$ /invite.html
It's meant to let a user access this url:
http://mysite.com/invite
and display the invite.html page. I don't want to redirect the user, but just show them the invite.html page from a better looking URL.
When I browse to http://mysite.com/invite though, I get a 404 not found error.
Is there anything I'm doing wrong? I've tried looking at tutorials for using mod_rewrite but I seem to be doing what they're telling me too...
Thanks!
I don't think there should be a / in that RewriteRule:
RewriteEngine on
RewriteRule ^invite$ invite.html
Did you make sure that AllowOverride All is set for the directory where the .htaccess file lies? Else the file might be ignored.
If this isn't the case, you should check out Apache's log files for more hints (/var/log/apache on Linux).
You're missing a RewriteCond directive. That's the one that does the actual testing Condition to match a URL. The RewriteRule is invoked only when one or more RewriteConds are matched.

Resources