How to rewrite part of the url with .htaccess? - drupal

I'm not that good with .htaccess, so I wonder, how can I rewrite default 'node' part of the url to an 'article' for example, so that server will output 'article/1' instead of 'node/1'. I need this to be done on a server side, so with the use of .htaccess only. Any guess?

The Pathauto module will allow you to set customised paths like this in Drupal. It's a must-have for Drupal (should be in Core, really). Just install and configure via the easy web-interface and you'll be all set.
You can even have different patterns for different node types. As an example, if you had 'page' and 'news' content types, your pages could have URLs like http://example.com/about-us while your news items could have urls like http://example.com/news/2009/05/28/news-post-title.

Well, the first problem is that you don't understand what mod_rewrite (which is what's doing the work you want, not .htaccess) does. It doesn't change the HTML you're outputting; it changes how the server interprets incoming URL requests.
So if your Drupal install understands node/1 and you want people to see article/1, first you need to modify the HTML output so it embeds links to article/1. Then you rewrite from article/1 to node/1 like so, in a .htaccess or Apache config file:
RewriteEngine on
RewriteRule article/ node/ [NS]

Related

How do I remove a word from a url in Wordpress using .htaccess?

In the site I'm building there is a post-type called "Focus". Since they need to url to be like www.mysite.com/focus/page-post-name I have the post type slug as "focus".
Of course the archive page is www.mysite.com/focus this is causing an issue since I need a specific page to be an archive page. Metaboxes are used to build and add settings to pages. I can't just create a page called "Focus" since that is reserved by the post-type.
My idea is to create a page called "Our Focus" resulting a URL of www.mysite.com/our-focus.
I'd like to just remove the "our-" from that url to make it appear that the archive is being used.
I've tried setting has_archive to false but that just reverts to using the archive.php page.
I'm mobile and working without access to a test server, so forgive any errors.
It sounds like you need mod_rewrite, it should be packaged with apache, but may be off. Typically you'll have to check the mods_enabled directory in your apache conf directory, or search your conf file for rewrite.
You'll need two lines in your htaccess at least.
RewriteEngine on
RewriteRule ^/focus/?$ /our-focus/
First line is required to enable rewrite.
The second line is the rule declaration, a regex to match, and a destination. The regex should only match focus, and direct you accordingly. Wordpress may take issue, but I think this will work.
Docs for reference
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
You may need RewriteBase depending on setup. RewriteBase is typically used if there are virtualHosts or a different base url then the server expects.

Replace all URL's for my WordPress site using a different domain name?

The domain names used are only examples, so if you could use those example names in your answer that would be great. I'm having a very hard time wording exactly what I'm trying to do and because of that can't find the answer via searching, so I'm posting it as this analogy:
I work for a company that makes WordPress sites. We'll call that company SuperMedia, and their main website is supermedia.com. SuperMedia wants to host their clients' sites on their own server via subfolders. So in this case, we've created a client's WordPress site in the directory http://supermedia.com/greatclient/
The issue is that our client has a domain name, friendlyclient.com, and we need to link this domain name to their site which we are hosting on our server, but we don't want the urls to show "supermedia" at all.
So in simplest terms, right now all of our page urls look like this:
http://supermedia.com/greatclient/about
http://supermedia.com/greatclient/our-services
http://supermedia.com/greatclient/gallery
(etc...)
But we want them all to say:
http://friendlyclient.com/about
http://friendlyclient.com/our-services
http://friendlyclient.com/gallery
(etc...)
but still display the information on http://supermedia.com/greatclient/about, http://supermedia.com/greatclient/our-services, http://supermedia.com/greatclient/gallery, etc. respectively.
Is there a simple, fairly fast way to do this for all the pages we've created, either using .htaccess or some kind of plugin? I don't have a lot of back-end programming/database knowledge, so if it involves advanced programming, could you lay-out some steps on how I can achieve this?
If you are using apache, you can use mod_rewrite to do the rewriting. Try adding this to your .htaccess file(In the friendlyclient.com root folder)
# Match the host
RewriteCond %{HTTP_HOST} ^([^\.]+)\.com$ [NC]
# proxy the entire request to the /host/ and path
RewriteRule ^(.*)$ http://www.supermedia.com/%1/$1 [L,P]
This will make it so requesting http://friendly.com/about will serve http://www.supermedia.com/friendlyclient/about and dont forget to rename ur folder, from greatclient to friedlyclient

Nginx rewrite rule

I need a rewrite rule for an nginx server. I'm using joomla 1.5 with sh404sef component to make clean urls.
Now i have installed gtranslate module to make the website multi language. So after installing the module my url's will change.
for example
My orginal url:
http://mywebsite.com/index.php?page=shop.product_details&flypage=flypage.tpl&product_id=511&option=com_virtuemart
the sh404sef component will change this to
http://mywebsite.com/men-s/coverall-shirt-in-grey.html
But after installing gtraslate the urls changed like this
I want to replace a url to something different. for example:
http://mywebsite.com/index.php?/ja/page=shop.product_details&flypage=flypage.tpl&product_id=511&option=com_virtuemart
here i have enabled japanese language, so there is a additional string /ja/ added in the url.
This is making problems in the website.
I want a rewrite rule for nginx to replace this url to orginal one without ja
Does anyone have an idea.
Please help me..
--
Thanks in Advance
Tibin Mathew
if you rewrite the url in ngingx your joomla will never receive the /ja request, and consequently will never server the translated content.
you'll have to make the sh404sef component work with the gtranslate url's instead
http://gtranslate.net/forum/gtranslate-fully-compatible-with-sh404sef-t2168.html indicates this should be possible, but doesn't say how

How WordPress permalink system works?

I am a php developer and i am currently developing a CMS/blog system. i want to add a permalink system like WordPress. i am curious about how WordPress parse permalink. For example, how to get data like id and post name from:
example.com/id/123/post/example/
In short, I want a system to get id and post name from the url. I want to enable users to change the permalink structure like WordPress using tags like:
id/%postid%/post/%postname%/
How do I get data in variables like $id and $post_name where values will 123 and example? Please help me.
Thanks in advance.
The commonly available apache module mod_rewrite can help you out with this. What you do is write rewrite rules inside an .htaccess file, and through the rewrite, fancy structures that would have normally resembled a file system get sent to a PHP file as $_GET parameters.
For example, if you wanted to replace something like: ?reactor=13 into /reactor/13/
Write this rewrite rule in the .htaccess file:
RewriteEngine on
RewriteRule reactor/([0-9]+)/$ index.php?id=$1
Now, if instead of index.php you pull up /reactor/13/, your index.php file should see this in $_GET:
Array
(
[id] => 13
)
Now, for your HTML code, it's up to you to craft URLs and obey your thought-out structure.
These rewrite rules can be confusing, but they follow a logical regex pattern.
WordPress takes a stronger approach than inserting these editing .htaccess files, to where they send everything to WP, and then WP solves / routes the rest through internal rules.
This depends on what server software you're using, but if your planning on using your scripts on Apache it, usually, involves using something called mod_rewrite and specifically a .htaccess file.
I would recommend starting by reading a tutorial on this subject. As usual, Google is your friend.

How to tackle existing url's when moving from Joomla to Drupal site

I've a Joomla site but I want to move it to Drupal-6 site. How should I go about changing existing url's? Should I add the redirection in .htacces or use any redirect modules?
One main reason of moving is the forum module in Drupal which I'd like to use.
I'd be using nodealias & global redirect modules.
In my site I'm using SH404SEF to generate urls(with .html suffix).
You can absolutely place a redirect in the .htaccess file and reference the pathauto generated path.
http://drupal.org/project/pathauto generates URL aliases based on title etc. and then put something like:
RewriteRule ^misc/about.html http://www.example.com/aboutus/ [R=301,L]
for each URL. (This is better off in your apache httpd.conf file for performance reasons.)
Or there is a module:
http://drupal.org/project/path_redirect
Which looks like it does just what you want but I've not tried it.

Resources