htaccess remove part of the url - .htaccess

I have urls structured like this:
/!#/pretty-url/
I need to remove the !# so the urls will look like this:
/pretty-url/
What would be the correct .htaccess rule to do this?

When you have a # in the URL then that is a named anchor. The browser does not send anything to the right of a # to the server. This means that all the rewrite engine is seeing is:-
/!
If you want your URLs to look like this then you are going to need to use JavaScript to get the relevant content via AJAX.

Related

i want a URL rewriting for my URL using only .htaccess file

My URL is
http://127.0.0.1/public_html/organisation/home/index.php?page=Your-Profile
but i want my url looks like this using .htaccess only:-
http://127.0.0.1/public_html/organisation/home/Your-Profile
i want to remove using .htaccess file index.php?page=
Please Help Me..
You can remove the /index.php as this is assumed/set by default by the engine, but you can't remove the ?page= as this is a query parameter, not part of the 'url' as you are thinking it. So it would look like http://127.0.0.1/public_html/organisation/home?page=Your-Profile
If you're using wordpress then there is an option in admin to set 'pretty urls' which would achieve this through other means.

String replacement with htaccess?

Some of my sites sometimes get encoded url queries which will redirect to a error page but i would like to support some of these.
With htaccess how could you replace a url like this:
http://website.com/%3Fpage%3Dbdyb2y21ybar3h35
With this:
http://website.com/?page=bdyb2y21ybar3h35
Edit: I would like to do this directly within the .htaccess rather than decode with PHP etc.

rewrite rule remove ugly code

i have reading different post but was't able to implement on my htaccess.
i have a url when i search on the page i get this url http://doman.se/module/spsearchpro/catesearch?fc=module&module=spsearchpro&controller=catesearch&orderby=name&orderway=desc&cat_id=2%2C4%2C9%2C6%2C5%2C10%2C8%2C7%2C11%2C36%2C37%2C50%2C21%2C29%2C22%2C24%2C23%2C53%2C31%2C30%2C32%2C52%2C12%2C13%2C39%2C25%2C14%2C33%2C34%2C43%2C35%2C44%2C40%2C51%2C15%2C16%2C20%2C19%2C41%2C49%2C42%2C46%2C45%2C48%2C27%2C38%2C28%2C47%2C54%2C55%2C56&search_query=general&spr_submit_search=Search&n=30
how can i remove the numbers 2%2C4%2C9%2C6%2C5%2C10%2C8%2C7%2C11%2C36%2C37%2C50%2C21%2C29%2C22%2C24%2C23%2C53%2C31%2C30%2C32%2C52%2C12%2C13%2C39%2C25%2C14%2C33%2C34%2C43%2C35%2C44%2C40%2C51%2C15%2C16%2C20%2C19%2C41%2C49%2C42%2C46%2C45%2C48%2C27%2C38%2C28%2C47%2C54%2C55%2C56
or make the url like this
http://doman.se/search_query=general

.htaccess rewrite url that has already been changed

I am upgrading my site which involves new scripts and a different URL
structure. There are currently a few thousand pages so I want to
basically move them in to a subdirectory so that they are not lost.
I am not very confident with htaccess so can someone please confirm that
the first part I have done is correct:
Old URL: http://www.example.com/article/another-dir/page-group/whatever.html
RewriteRule ^article/?$ http://www.example.com/archive/ [R=301,NC,L]
To achieve this: http://www.example.com/archive/another-dir/page-group/whatever.html
Search engines will see the above as a permanent move and in the address bar
it will show the new url. Is this right?
The second part is on the new script - the url's could be improved but I am
unable to change all the script so thought about using htaccess again but am
not sure if it can be achieved like this.
At the moment the url looks like this:
url: http://www.example.com/category/4/categoryname
In the htaccess the current rewrite rule for this type of url looks like this:
RewriteRule ^category/(.*)/(.*)$ category.php?id=$1&slug=$2
Is it possible to change this so that in the url address bar I end up
with this:
http://www.example.com/categoryname
Basically I don't want to see either the number or category/ in the resulting
url as it will be easier for visitors to use - is that possible??
Thanks in advance for any help.
The second question related to passing in URI components for querystring redirect and then hiding those components in the URL I don't think would be easy, if even possible, using RewriteRules.
For the first question though. Given the sample URLs you mentioned, the RewriteRule would need to include capture and backreference if you want to preserve the full URL in the redirection. For example:
RewriteRule ^article/?(.*)$ http://www.example.com/archive/$1 [R=301,NC,L]

links includes coma and hash htaccess

I'm using links like that:
find.php?id=1&n=2#loc
I want to my links look like:
but i dont know how to change htaccess and when/where use # to link some place in the page #loc
htaccess:
RewriteRule ^(.*),(.*),(.*)$ $3.php?id=$2&n=$1 [L,NC,NS,NE]
Help lease
The #loc part of the URL is never sent to the server, so there's no way for you to match against it in your htaccess file. Anything starting from the # in the URL is called a fragment and it's used by the browser, the server doesn't know it's even there.

Resources